这是我用过的代码
\documentclass[12pt]{article}
\usepackage{fullpage}
\usepackage[british]{babel}
\usepackage{graphicx}
\usepackage{natbib}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{tikz}
\def\checkmark{\tikz\fill[scale=0.4](0,.35) -- (.25,0) -- (1,.7) -- (.25,.15) -- cycle;}
\linespread{1.2}
\begin{longtable}{@{}llllll@{}}
\caption{}
\label{Table 2}\\
Regression 1B: & & &
\\
\endfirsthead
%
\multicolumn{6}{c}%
{{\bfseries Table \thetable\ continued from previous page}} \\
\endhead
%
\multicolumn{6}{l}{2012 reform} \\* \midrule
Logit estimates & Model 1 & Model 2 & Model 3 & Model 4 & Model 5 \\* \midrule
Entry year & -.091*** & -.077*** & -.063*** & -.102*** & -.064*** \\
& (0.000) & (0.000) & (0.001) & (0.003) & (0.002) \\
Female & & .883*** & .833*** & .798*** & .833*** \\
& & (0.000) & (0.000) & (0.000) & (0.000) \\
BAME & & -.700*** & -.618*** & -.618*** & -.620 \\
& & (0.000) & (0.000) & (0.000) & (0.000) \\
Female x entry year & & & & \checkmark & \\
BAME x entry year & & & & & \checkmark \\* \midrule
Controls & & & \checkmark & \checkmark & \checkmark \\* \midrule
Observations & 165,280 & 165,280 & 165,280 & 165,280 & 165,282 \\
Reported coefficients; p-values in parentheses & & & & & \\
*** p\textless{}0.01, ** p\textless{}0.05, * p\textless{}0.1 & & & & &
\end{longtable}
如何让表格保持在页面边框内。因为它目前向右偏离,并且也与底部的页码重叠
答案1
直接的方法是创建\multicolumn
最后两行。
\documentclass[12pt]{article}
\usepackage{fullpage}
\usepackage[british]{babel}
\usepackage{graphicx}
\usepackage{natbib}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{tikz}
\def\checkmark{\tikz\fill[scale=0.4](0,.35) -- (.25,0) -- (1,.7) -- (.25,.15) -- cycle;}
\linespread{1.2}
\begin{document}
\begin{longtable}{@{}llllll@{}}
\caption{}
\label{Table 2}\\
Regression 1B: & & &
\\
\endfirsthead
%
\multicolumn{6}{c}%
{{\bfseries Table \thetable\ continued from previous page}} \\
\endhead
%
\multicolumn{6}{l}{2012 reform} \\* \midrule
Logit estimates & Model 1 & Model 2 & Model 3 & Model 4 & Model 5 \\* \midrule
Entry year & -.091*** & -.077*** & -.063*** & -.102*** & -.064*** \\
& (0.000) & (0.000) & (0.001) & (0.003) & (0.002) \\
Female & & .883*** & .833*** & .798*** & .833*** \\
& & (0.000) & (0.000) & (0.000) & (0.000) \\
BAME & & -.700*** & -.618*** & -.618*** & -.620 \\
& & (0.000) & (0.000) & (0.000) & (0.000) \\
Female x entry year & & & & \checkmark & \\
BAME x entry year & & & & & \checkmark \\* \midrule
Controls & & & \checkmark & \checkmark & \checkmark \\* \midrule
Observations & 165,280 & 165,280 & 165,280 & 165,280 & 165,282 \\ \bottomrule
\multicolumn{6}{l}{Reported coefficients; p-values in parentheses} \\
\multicolumn{6}{l}{ *** p\textless{}0.01, ** p\textless{}0.05, * p\textless{}0.1}
\end{longtable}
答案2
- 你真的需要吗
longtable
?从代码片段可以得出结论,不需要,因此,你可以使用长表来代替,例如tabularx
,对于下表的注释,使用tablenotes
由以下公式确定的\threeparttablex
:
\documentclass[12pt]{article}
\usepackage{fullpage}
\usepackage{dingbat}
\usepackage[skip=1ex]{caption}
\usepackage{booktabs, xltabular}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\NewExpandableDocumentCommand\mcx{O{1}m}{\multicolumn{#1}{X}{#2}}
\usepackage[referable]{threeparttablex}
\usepackage{siunitx}
%---------------------------------------------------------------%
\usepackage{lipsum}% For dummy text. Don't use in a real document
\begin{document}
\lipsum[1-2]
\begin{table}[ht]
\sisetup{table-space-text-pre={(},
table-align-text-pre=false,
table-space-text-post={***},
table-align-text-post=false,
input-open-uncertainty = ,
input-close-uncertainty = ,
table-format=-1.3
}
\begin{threeparttable}
\caption{My long table}
\label{Table 2}
\begin{tabularx}{\linewidth}{@{} l *{5}{S} @{}}
\toprule
\multicolumn{6}{@{} l}{2012 reform} \\*
\midrule
\multicolumn{6}{@{} l}{Regression 1B:} \\
Logit estimates
& \mcx{Model 1} & \mcx{Model 2} & \mcx{Model 3} & \mcx{Model 4} & \mcx{Model 5} \\*
\midrule
Entry year
& -.091*** & -.077*** & -.063*** & -.102*** & -.064*** \\
& (0.000) & (0.000) & (0.001) & (0.003) & (0.002) \\
Female
& & .883*** & .833*** & .798*** & .833*** \\
& & (0.000) & (0.000) & (0.000) & (0.000) \\
BAME
& & -.700*** & -.618*** & -.618*** & -.620 \\
& & (0.000) & (0.000) & (0.000) & (0.000) \\
Female x entry year
& & & &\checkmark & \\
BAME x entry year
& & & & &\checkmark \\*
\midrule
Controls
& & &\checkmark & \checkmark &\checkmark \\*
\midrule
Observations
& {165,280} & {165,280} & {165,280} & {165,280} & {165,282} \\
\bottomrule
\end{tabularx}
\begin{tablenotes}[para,flushleft]\footnotesize
\note{
Reported coefficients; $p$-values in parentheses:
\item[***] $p<0.01$,
\item[**] $p<0.05$,
\item[*] $p<0.1$
}
\end{tablenotes}
\end{threeparttable}
\end{table}
\lipsum[3]
\end{document}
- 如果你出于某些未知原因坚持要在页面之间拆分表格,那么我会考虑使用
xltabular
和threeparttablex
包。此外,为了更好地对齐数字,我会使用siunitx
包和\checkmark
使用字体dingbat
:
\documentclass[12pt]{article}
\usepackage{fullpage}
\usepackage{dingbat}
\usepackage[skip=1ex]{caption}
\usepackage{booktabs, xltabular}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\NewExpandableDocumentCommand\mcx{O{1}m}{\multicolumn{#1}{C}{#2}}
\usepackage[referable]{threeparttablex}
\usepackage{siunitx}
%---------------- Show page layout. Don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}% For dummy text. Don't use in a real document
\begin{document}
\lipsum[1-4]
\begingroup
\sisetup{table-space-text-pre={(},
table-align-text-pre=false,
table-space-text-post={***},
table-align-text-post=false,
input-open-uncertainty = ,
input-close-uncertainty = ,
table-format=-1.3
}
\begin{ThreePartTable}
\begin{TableNotes}[para,flushleft]\footnotesize
\note{Reported coefficients; $p$-values in parentheses:
\item[***] $p<0.01$,
\item[**] $p<0.05$,
\item[*] $p<0.1$
}
\end{TableNotes}
%
\begin{xltabular}{\textwidth}{@{} l *{5}{S} @{}}
\caption{My long table}
\label{Table 2} \\
\toprule
Regression 1B: & & & \\
\midrule
\endfirsthead
\caption[]{ continued from previous page} \\
\endhead
%\endfoot
\bottomrule
\insertTableNotes
\endlastfoot
% table body
\multicolumn{6}{@{} l}{2012 reform} \\*
\midrule
\multicolumn{6}{@{} l}{Regression 1B:} \\
Logit estimates
& \mcx{Model 1} & \mcx{Model 2} & \mcx{Model 3} & \mcx{Model 4} & \mcx{Model 5} \\*
\midrule
Entry year
& -.091*** & -.077*** & -.063*** & -.102*** & -.064*** \\
& (0.000) & (0.000) & (0.001) & (0.003) & (0.002) \\
Female
& & .883*** & .833*** & .798*** & .833*** \\
& & (0.000) & (0.000) & (0.000) & (0.000) \\
BAME
& & -.700*** & -.618*** & -.618*** & -.620 \\
& & (0.000) & (0.000) & (0.000) & (0.000) \\
Female x entry year
& & & &\checkmark & \\
BAME x entry year
& & & & &\checkmark \\*
\midrule
Controls
& & &\checkmark & \checkmark &\checkmark \\*
\midrule
Observations
& {165,280} & {165,280} & {165,280} & {165,280} & {165,282} \\
\end{xltabular}
\end{ThreePartTable}
\endgroup
\lipsum[5]
\end{document}
(红线表示页面布局)