
아래 그림과 같은 테이블을 구성하고 싶습니다.
아래 코드는 지금까지의 최선의 시도를 나타냅니다(표의 단어는 실제로 아무 의미도 없습니다).
\resizebox{9cm}{!} {
\begin{tabular}{l*{2}{c}r}
Model & Linear Regression && MLE \\
\hline
fakedata50 & -1.037 & &4 \\
fakedata100 & -1.038 && 3 \\
fakedata500 & -0.7859 && 2 \\
fakedata5000 &-0.7742 && 2 \\
fakedata10000 &-0.7665&&o \\
fakedata100000 &-0.7206&&j \\
fakedata1000000 &-0.6939&&j \\
\end{tabular} }
그러나 테이블을 중앙에 배치하고 싶지만 명령이 \centering
작동하지 않습니다.
그리고 의 값을 변경하여 그래프를 확대하려고 하면 \resizebox
글꼴 크기도 커지는 현상이 발생하여 바람직하지 않습니다. 표를 확대하는 정도에 비례하여 글꼴 크기를 늘리는 방법이 있습니까?
마지막으로, 테이블 제목을 어떻게 조판할 수 있나요?
답변1
테이블을 구성할 때,booktabs
패키지는 가장 친한 친구입니다. 귀하의 특별한 경우에는siunitx
소수점 정렬을 돕기 위한 패키지입니다(물론 패키지는 열 정렬 외에도 더 많은 작업을 수행할 수 있습니다).
열 S
유형은 선택적 인수를 사용합니다. 이를 통해 각 개별 열을 조정할 수 있습니다. 나는 table-format=1.4
이 열에 1
숫자 가 있다는 것을 자세히 설명하곤 했습니다.~ 전에소수점과 4
그 뒤의 숫자. {Linear Regression}
수학 모드와 소수점 정렬 루틴에서 '이스케이프'하기 위해 열 머리글을 묶어야 한다는 점을 기억하실 것입니다 .
여기에 여러분이 가지고 놀 수 있는 완전한 코드가 있습니다.
% arara: pdflatex
% !arara: indent: {overwrite: yes}
\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}
\begin{document}
\begin{tabular}{lS[table-format=1.4]r}
\toprule
Model & {Linear Regression} & MLE \\
\midrule
fakedata50 & -1.037 & 4 \\
fakedata100 & -1.038 & 3 \\
fakedata500 & -0.7859 & 2 \\
fakedata5000 & -0.7742 & 2 \\
fakedata10000 & -0.7665 & o \\
fakedata100000 & -0.7206 & j \\
fakedata1000000 & -0.6939 & j \\
\bottomrule
\end{tabular}
\end{document}
에 대한 '제목'을 만들고 싶다면 table
다음 명령을 사용해야 합니다 caption
. tabular
환경을 환경 내에 배치하거나 table
그렇지 않으면 패키지 captionof
의 명령을 사용해야 합니다 caption
.
% arara: pdflatex
% !arara: indent: {overwrite: yes}
\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}
\begin{document}
\begin{table}[!ht]
\centering
\caption{Your caption goes here}
\begin{tabular}{lS[table-format=1.4]r}
\toprule
Model & {Linear Regression} & MLE \\
\midrule
fakedata50 & -1.037 & 4 \\
fakedata100 & -1.038 & 3 \\
fakedata500 & -0.7859 & 2 \\
fakedata5000 & -0.7742 & 2 \\
fakedata10000 & -0.7665 & o \\
fakedata100000 & -0.7206 & j \\
fakedata1000000 & -0.6939 & j \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
답변2
표준 tabular
환경에서도 테이블 크기를 조정하기 위한 도구가 제공됩니다. 가장 눈에 띄는 점은 길이에 따라 tabcolsep
각 열 측면의 패딩이 조정된다는 점입니다. 내 예에서는 테이블을 표준에 맞추기 위해 크기를 줄여야 했지만 \textwidth
귀하의 경우에는 값을 높일 수 있습니다. 마찬가지로 글꼴 크기를 로 변경했지만 \small
공간이 문제가 되지 않거나 문서 전체의 일관성을 유지하기 위해 그렇게 할 필요는 없습니다.
\renewcommand\arraystretch{}
수직 공간의 경우 테이블 행 사이의 공간을 늘리는 데 사용합니다 . 환경에 들어가면 \centering
잘 작동합니다. 환경 외부에서 사용할 때는 {\centering my table stuff \par}
. 중괄호는 수용된 항목으로만 중심 맞춤 범위를 제한합니다. 그리고 \par
을(를) 활성화하려면 이 필요합니다 \centering
.
\documentclass{article}
\usepackage{lipsum}
\usepackage{stackengine}
\def\twostack#1#2{\addstackgap{\stackanchor[0pt]{\strut#1}{\strut#2}}}
\begin{document}
\lipsum[1]
\begin{table}[ht]
\centering
\renewcommand\arraystretch{2}
\tabcolsep 3pt
\caption{Chi-square analysis for data set Total Site 1}
\medskip\small
\begin{tabular}{ccccccc}
\hline
\hline
\textbf{Model} & \textbf{Parameters} & \textbf{Estimates} &
\textbf{\twostack{Chi-square}{statistic}} &
\textbf{P-value} & \textbf{Outcome} & \\
\hline
Geometric Series & $k$ & 0.129202 & 17019.3 & $<$0.001 & Reject\\
\twostack{Broken Stick}{(binned)} & - & - & 1430.72 & $<$0.001 & Reject\\
\twostack{Broken Stick}{(rank abundance)} & - & - & 120085 & $<$0.001 & Reject\\
Logseries & \twostack{$\alpha$}{$x$} & &&&...\\
\hline
\hline
\end{tabular}
\end{table}
\lipsum[2]
\end{document}
답변3
OP에서 예로 제시한 표의 시작 부분이 더 복잡하기 때문에 다시 실행해 보았습니다. 소수점 정렬이 적합한 열에는 , 및 booktabs
패키지 caption
를 사용했습니다 . 이러한 열( 유형 )에서 셀에 숫자가 아닌 자료가 포함될 때마다 대괄호로 묶어야 합니다.makecell
numprint
n{…}{…}
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[showframe, nomarginpar, noheadfoot]{geometry}
\usepackage{fourier}
\usepackage{heuristica}
\usepackage{array}
\usepackage{booktabs}
\usepackage{caption}
\captionsetup{labelfont = sc, labelsep = period, justification = centering }
\usepackage{makecell}
\renewcommand\theadfont{\bfseries}
\usepackage[autolanguage, np]{numprint}
\usepackage{stackengine}
\usepackage[english]{babel}
\begin{document}
\begin{table}[!h]
\centering
\caption{Chi-square analysis for data set\enspace Total Site 1}
\begin{tabular}{c >{$}c<{$} n{2}{7}c >{$}n{1}{5}<{$} c}
\toprule\midrule
\thead{Model} & \thead{\textbf{Parameters}} & {\thead{Estimates}} & \thead{Chi-square \\ statistics} & \thead{\textbf{P-value}} & \thead{Outcome} \\
\midrule
\addlinespace
Geometric Series & k & 0.129202 & 17019.3 & < 0.001 & Reject \\
\makecell*{Broken Stick \\ (binned)} & - & {\makecell{--}} & 1430.72 & < 0.001 & Reject \\
\makecell{Broken Stick \\ (rank abundance)} & - & {\makecell{--}} & 120085 & < 0.001 & Reject \\
\multirowcell{2}{Logseries} & α &7.287017 & \multirowcell{2}{20.44702} & {\multirowcell{2}{0.11667}} & Cannot \\%
& x & 0.9999327 & & & reject \\[3pt]
\multirowcell{2}{Lognormal} & M & 6.67146 & \multirowcell{2}{30.8349} & {\multirowcell{2}{< 0.001}} & \multirowcell{2}{Reject} \\
& V & 16.0206 \\
\midrule\bottomrule
\end{tabular}
\end{table}
\end{document}