Latex에서 멋진 테이블을 어떻게 만들 수 있습니까?
깔끔하게 보이는 테이블을 만들 수 있습니다. 다음과 같은 테이블을 만드는 방법이 궁금합니다.

\begin{table}[htbp]
\caption{Variable Descriptions}
\label{tab:2}
\begin{center}
\begin{tabular}{|c|c|}\hline
Variables & Descriptions\\\hline
\textit{ln(wage)} & log of wage\\
\textit{educ} & years of education\\
\textit{black} & 1 if black and 0 if not\\
\textit{hisp} & 1 if hispanic and 0 if not\\
\textit{exper} & years of experience\\
\textit{exper$^{2}$} & years of experience squared\\
\textit{married} & 1 if married and 0 if not\\
\textit{union} & 1 if belongs to a union and 0 if not\\\hline
\end{tabular}
\end{center}
\end{table}
특정 질문은 다음과 같습니다.
- 회색과 흰색 사이에 하나의 행 색상이 어떻게 번갈아 표시 될까요? 수동으로 색상을 지정하는 대신 명령을 만드는 방법이 있습니까?
답변
다음은 테이블의 세 가지 버전입니다.

\documentclass{article}
\usepackage[table,svgnames]{xcolor} % provides the \rowcolors command
\usepackage{caption} % for improved spacing around the caption
\usepackage{array} % enables >{...} in the coumn specifier section, used in table 2 & 3
\usepackage{booktabs} % for improved spacing around horizontal lines, used in example 3, incompatible with vertical lines, be careful if you want to to combine it with color
\usepackage[column=0]{cellspace} % for adding a small amount of space above and below each cell, only used in table 2
\setlength{\cellspacetoplimit}{2pt}
\setlength{\cellspacebottomlimit}{\cellspacetoplimit}
\begin{document}
\begin{table}[htbp]
\caption{Variable Descriptions}
\label{tab:2}
\centering % used \centering instead of the center environment since the latter adds additional white space
\rowcolors{2}{white}{lightgray}
\begin{tabular}{|c|c|}\hline
Variables & Descriptions\\\hline
\textit{ln(wage)} & log of wage\\
\textit{educ} & years of education\\
\textit{black} & 1 if black and 0 if not\\
\textit{hisp} & 1 if hispanic and 0 if not\\
\textit{exper} & years of experience\\
\textit{exper$^{2}$} & years of experience squared\\
\textit{married} & 1 if married and 0 if not\\
\textit{union} & 1 if belongs to a union and 0 if not\\\hline
\end{tabular}
\end{table}
\begin{table}[htbp]
\caption{Variable Descriptions}
\label{tab:2}
\centering
\rowcolors{2}{white}{lightgray}
\begin{tabular}{>{\itshape}0l0l}\hline % used >{\itshape} in order to be able to remove the repeated occurences of \textit in the first column, used l type columns instead of c columns for a cleaner look, added small vertical space above and below the rows with the help of the cellspace package, removed all vertical lines
\textup{Variables} & Descriptions\\\hline
ln(wage) & log of wage\\
educ & years of education\\
black & 1 if black and 0 if not\\
hisp & 1 if hispanic and 0 if not\\
exper & years of experience\\
exper\textsuperscript{2} & years of experience squared\\
married & 1 if married and 0 if not\\
union & 1 if belongs to a union and 0 if not\\\hline
\end{tabular}
\end{table}
\begin{table}[htbp]
\caption{Variable Descriptions}
\label{tab:2}
\centering
\begin{tabular}{>{\itshape}ll}
\toprule % replaced all \hline commands with rules from the booktabs package
\textup{Variables} & Descriptions\\
\midrule
ln(wage) & log of wage\\
educ & years of education\\
black & 1 if black and 0 if not\\
hisp & 1 if hispanic and 0 if not\\
exper & years of experience\\
exper\textsuperscript{2} & years of experience squared\\
married & 1 if married and 0 if not\\
union & 1 if belongs to a union and 0 if not\\
\bottomrule
\end{tabular}
\end{table}
\end{document}
질문의 핵심에 답하겠습니다. I am wondering how to create tables like this.
실험 결과부터 월 예산까지 항상 테이블 작업을합니다. 정렬, 서식 지정, 확인 및 간단한 데이터 분석과 같은 작업의 경우 Excel에서 수행합니다 (2013 년 사용). 최종 테이블은 결국 많은 반복과 시간 후에 나옵니다.
귀하의 예에서 데이터가 데이터베이스에서 나오고 모든 패치 및 모든 수정 사항에 대한 수직 누적 결과, 일관성에 대한 교차 검사 등이 있음이 분명합니다.
LaTeX는 아름다운 보고서를 게시하기위한 것이지만 이것은 일년에 몇 번 발생합니다. 매우 간단한 테이블에서만 데이터를 LaTeX에 직접 쓸 수 있습니다.
내 Excel에서 LaTeX 로의 워크 플로우에는 3 단계가 있습니다.
1 Excel에서 필요한 스타일로 최종 표의 서식을 지정합니다. 필요에 따라 색상, 눈금자 등을 사용합니다.

- CTAN의 Excel2Latex 추가 기능을 사용하여 테이블을 내 보냅니다. 설치가 쉽고 광고 된대로 작동합니다.
https://ctan.org/tex-archive/support/excel2latex?lang=en
클립 보드에 복사하여 기본 LaTeX 문서에 붙여 넣습니다.

몇 가지 기본 패키지를 추가하고 (내 예제 참조) 결과 코드를 실행해야합니다.
다중 행, 색상 및 가장 중요한 내용과 같은 대부분의 기능이 LaTeX에 성공적으로 전달되었음을 알 수 있습니다. 스타일의 세부 사항에 대해 마음이 바뀌면 Excel 시트를 쉽게 편집하고 LaTeX 코드를 다시 생성 할 수 있습니다.
3 LaTeX 명령을 사용하여 글꼴, 늘이기, 하이픈, 기호 등의 마무리 터치를 적용합니다.
예를 들어, caption
원본 캡션과 일치 하는 패키지를 포함하고 첫 번째 행에 위첨자를 추가하고 두 번째 행에 undeline을 추가하고 필요에 따라 작은 대문자를 추가했습니다. 내가 사용하는 arraystretch
수직 셀을 확장 1.3.
이 특별한 경우에는 아래쪽 셀 배경이 셀 내용의 일부를 덮어 쓰지 않도록 이중 회색 행에 아래로 7 포인트 오프셋을 포함해야했습니다. 이것은 컬러 셀로 작업 할 때 흔히 발생합니다. 댓글 [7pt]
을 달고 무슨 일이 일어나는지 확인하십시오.
물론 하나의 배경색 만 사용하면 모든 것이 좋아 보일 것입니다! 그러나 대체 행 색상 스타일이 매우 훌륭하고 넓은 다중 열 테이블에서 필수라는 것을 알았습니다. 비머 프레젠테이션은 흑백 만 사용하면 파멸 될 것입니다.
\documentclass[12pt,a4paper]{book}
\RequirePackage[table]{xcolor}
\RequirePackage{booktabs}
\RequirePackage{multirow}
\RequirePackage{caption}% typesetting of captions
\captionsetup{%
labelfont={bf}, %Table 1
textfont={bf} %caption font
}%
\begin{document}
% Table generated by Excel2LaTeX from sheet 'Sheet1'
\begin{table}[htbp]
\renewcommand{\arraystretch}{1.3} % expand the rows vertically
\setlength\belowcaptionskip{8pt}
\centering
\caption{Test--suite based program repair tools for Java.}
\begin{tabular}{llrrr}
\toprule
\multicolumn{1}{c}{\multirow{2}[2]{*}{Repear tool}} & Benchmark used & \multicolumn{1}{r}{\multirow{2}[2]{*}{\# Bugs}} & \multirow{2}[2]{*}{\# Patched\textsuperscript{a}} & \multirow{2}[2]{*}{\# Fixed\textsuperscript{b}} \\
& in evaluation & & & \\
\midrule
\multicolumn{5}{l}{\underline{\emph{Generate--and--validate}}} \\
\rowcolor[rgb]{ .906, .902, .902} ACS [4] & Defects4J & 224 & 23 & 17 \\
\multirow{2}[0]{*}{ARJA [50]} & Defects4J & 224 & 59 & 18 \\
& QuixBugs [48] & 40 & 4 & 2 \\
\rowcolor[rgb]{ .906, .902, .902} \multirow{2}[1]{*}{\textsc{CapGen} [42]} & Defects4J & 224 & 25 & 22 \\[7pt] % shift needed for colored multirows
\rowcolor[rgb]{ .906, .902, .902} & IntroClassJava & 297 & -- & 25 \\
\multirow{2}[0]{*}{Cardumen [28]} & Defects4J & 356 & 77 & -- \\
& QuixBugs [48] & 40 & 5 & 3 \\
\rowcolor[rgb]{ .906, .902, .902} DeepRepair [43] & Defects4J & 374 & 51 & -- \\
\multirow{2}[0]{*}{\textsc{Elixir} [37]} & Defects4J & 82 & 41 & 26 \\
& Bugs.jar & 127 & 39 & 22 \\
\rowcolor[rgb]{ .906, .902, .902} GenProg-A & Defects4J & 224 & 36 & -- \\
HDRepair [18] & Defects4J & 90 & -- & 23 \\
\rowcolor[rgb]{ .906, .902, .902}\textsc{Jaid} [2] & Defects4J & 138 & 31 & 25 \\
\multirow{3}[0]{*}{jGenProg [27]} & Defects4J & 224 & 29 & -- \\
& Defects4J [26] & 224 & 27 & 5 \\
& QuixBugs [48] & 40 & 2 & 0 \\
\ldots & \ldots & \ldots & \ldots & \ldots \\ % more rows follows
\bottomrule
\multicolumn{5}{l}{\footnotesize \textsuperscript{a} As reported last week. \ \textsuperscript{b} Verified by QC. }\\
\end{tabular}%
\label{tab:addlabel}%
\end{table}%
\end{document}
이것이 최종 결과입니다. 주로 데이터 입력 및 시트 서식 지정에 소요되는 총 시간은 1 ~ 2 시간입니다.

테이블 그냥 마감 전에 당신의 상사에 의해 요청에 최종 연습으로, 다른 열을 추가하십시오 : Still Missing
이다 (엑셀 시트에서 계산) 데이터와 Bugs
마이너스 Patches
마이너스 Fixed
어떻게 모든 작품을보고 (이 걸리는 약간의 시간과!) . 실제 상황.
비고 : 이 답변에는 버전 5.2 (2020-08-19)가 필요합니다 nicematrix
.
OP가 제공하는 이미지는 행이 번갈아 표시됩니다. 그러나 일부 행은 실제로 여러 행의 재결합입니다. 이 상태에서는 사용하기 어려운 \rowcolors
중 xcolor
. 최신 버전 nicematrix
(2020-08-19의 v. 5.2)에서 기본 제공 명령어 \rowcolors
(에서 사용 예정 code-before
)에는 respect-blocks
해당 문제를 처리 할 수 있는 옵션 이 있습니다. 블록을 포함하는 행은 하나의 행으로 만 간주됩니다.
\documentclass{article}
\usepackage{nicematrix}
\usepackage{multirow}
\usepackage{booktabs}
\usepackage{makecell}
\usepackage{enumitem}
\NiceMatrixOptions{notes = { para , style = \alph{#1} } }
\begin{document}
\begin{NiceTabular}{ll@{\space}lrrr}%
[ code-before = \rowcolors{3}{gray!20}{}[respect-blocks] ]
\toprule
Repair tool &
\multicolumn{2}{l}{\makecell[l]{Benchmark used\\ in evaluation}}
&
\# Bugs &
\# Patched\tabularnote{Note}&
\# Fixed\tabularnote{Note}\\
\midrule
\underline{\emph{Generate-and-validate}} \\
ACS [46] & Defects4J & & 224 & 23 & 17 \\
\Block{2-1}{}\multirow{2}{*}{ARJA [50]} & Defects4J& & 224 & 59 & 18 \\
& QuixBugs& [38] & 40 & 4 & 2 \\
\Block{2-1}{}\multirow{2}{*}{\textsc{CapGen} [42]} & Defects4J& & 224 & 25 & 22 \\
& \rlap{IntroClassJava} & & 297 & -- & 25 \\
\Block{2-1}{}\multirow{2}{*}{Cardumen [28]} & Defects4J& & 356 & 77 & -- \\
& QuixBugs& [48] & 40 & 5 & 3 \\
DeepRepair [43] & Defects4J& & 374 & 51 & - \\
\Block{2-1}{}\multirow{2}{*}{\textsc{Elixir} [37]} & Defects4J& & 82 & 41 & 26 \\
& Bugs.jar & & 127 & 39 & 22 \\
GenProg-1 [50] & Defects4J& & 224 & 36 & -- \\
HDRepair [18] & Defects4J& & 90 & -- & 23 \\
\textsc{Jaid} [2] & Defects4J& & 138 & 31 & 25 \\
\Block{3-1}{}\multirow{3}{*}{jGenProg [27]} & Defects4J & & 224 & 29 & -- \\
& Defects4J & [26] & 224 & 27 & 5 \\
& QuixBugs& [48] & 40 & 2 & 0 \\
\Block{3-1}{}\multirow{3}{*}{jKali [27]} & Defects4J& & 224 & 22 & -- \\
& Defects4J& [26] & 224 & 22 & 1 \\
& QuixBugs& [48] & 40 & 2 & 1 \\
\Block{2-1}{}\multirow{2}{*}{jMutRepair [27]} & Defects4J& & 224 & 17 & -- \\
& QuixBugs& [48] & 40 & 3 & 1 \\
Kali-A [50] & Defects4J& & 224 & 33 & -- \\
LSRepair [23] & Defects4J& & 395 & 38 & 19 \\
PAR [17] & \rlap{PARDataset} & & 119 & 27 & -- \\
\Block{2-1}{}\multirow{2}{*}{PSRepair-A [50]} & Defects4J& & 224 & 44 & -- \\
& QuixBugs& [48] & 40 & 4 & 2 \\
SimFix [14] & Defects4J& & 357 & 56 & 34 \\
\textsc{SketchFix} [13] & Defects4J& & 357 & 26 & 19 \\
SOFix [24] & Defects4J& & 224 & -- & 23 \\
ssFix [45] & Defects4J& & 357 & 60 & 20 \\
xPar [18] & Defects4J& & 90 & -- & 4 \\
\bottomrule
\end{NiceTabular}
\end{document}

이건 어때? ( matrix
TikZ 사용)

\documentclass[tikz,border=5mm]{standalone}
\usepackage{amsmath,amssymb,amsthm}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix (m) [matrix of nodes,draw=teal,thick,inner sep=.5pt,
nodes in empty cells,
row sep=-\pgflinewidth,
column sep=-\pgflinewidth,
nodes={minimum height=9mm,anchor=center},
row 1/.style={nodes={font=\bfseries}},
column 1/.style={nodes={minimum width=2.5cm,text width=1.5cm,align=left,font=\itshape}},
column 2/.style={nodes={minimum width=7cm,text width=6cm,align=left}},
every even row/.style={nodes={fill=cyan!20}}
]{
Variables & Descriptions\\
ln(wage) & log of wage\\
educ & years of education\\
black & 1 if black and 0 if not\\
hisp & 1 if hispanic and 0 if not\\
exper & years of experience\\
exper\textsuperscript{2} & years of experience squared\\
married & 1 if married and 0 if not\\
union & 1 if belongs to a union and 0 if not\\
};
\end{tikzpicture}
\end{document}