使用小表格防止 parbox 向右移动

使用小表格防止 parbox 向右移动

我有一张小表格,我想在底部添加一些文本,但是因为它太小,所以它会向右移动,我不知道如何纠正这个问题。

\documentclass[10pt]{article}
\usepackage{graphicx}
\usepackage{pdflscape}
\usepackage{dcolumn}
\usepackage[a4paper, total={8in, 10in}]{geometry}
\begin{document}

\begin{table}[!htbp] \centering 
  \caption{Table} 
  \label{} 
\begin{tabular}{@{\extracolsep{5pt}} cc} 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
Position & Percentage \\ 
\hline \\[-1.8ex] 
A & 5.5\% \\ 
B & 2.5\% \\ 
C & 1\% \\ 
D & 91\% \\ 
\hline \\[-1.8ex] 
\end{tabular}
\parbox{1.3in}{Notes: This is a table with text that ends up on the right side of the table}
\end{table}
\end{document}

在此处输入图片描述

答案1

有两种方法可以实现此目的:

\documentclass[10pt]{article}
\usepackage{graphicx}
\usepackage{pdflscape}
\usepackage{dcolumn}
\usepackage[a4paper, total={8in, 10in}]{geometry}
\usepackage[flushleft]{threeparttable} %Needed for second solution only
\begin{document}

\begin{table}[!htbp] \centering 
  \caption{Table} 
  \label{} 
\begin{tabular}{@{\extracolsep{5pt}} cc} 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
Position & Percentage \\ 
\hline \\[-1.8ex] 
A & 5.5\% \\ 
B & 2.5\% \\ 
C & 1\% \\ 
D & 91\% \\ 
\hline \\[-1.8ex] 
\end{tabular}\vspace{-10pt}
\begin{center}
\parbox{1.3in}{Notes: This is a table with text that ends up on the right side of the table}
\end{center}
\end{table}


\begin{table}[!htbp] \centering
  \begin{threeparttable}
  \caption{Table} 
  \label{} 
\begin{tabular}{@{\extracolsep{5pt}} cc} 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
Position & Percentage \\ 
\hline \\[-1.8ex] 
A & 5.5\% \\ 
B & 2.5\% \\ 
C & 1\% \\ 
D & 91\% \\ 
\hline \\[-1.8ex] 
\end{tabular}
\begin{tablenotes}
      \small
      \item Notes: This is a table with text that ends up on the right side of the table
\end{tablenotes}
  \end{threeparttable}
\end{table}
\end{document}

第二种用途threeparttable是使用这类表格的通用包。

第一个只是一个中心环境,它可以产生效果...但是 htis 将创建一个额外的垂直空间,您可以使用 vspace 命令减去它。

输出:

在此处输入图片描述

答案2

tablenotes使用的环境来执行此操作要好得多threeparttable。此外,我还简化了使用 的规则向水平规则添加一些填充的方法booktabs,其中内置了此填充:

\documentclass[10pt]{article}
\usepackage{graphicx}
\usepackage{pdflscape}
\usepackage{dcolumn}
\usepackage{threeparttable, booktabs}
\usepackage[a4paper, total={8in, 10in}]{geometry}

\begin{document}

\begin{table}[!htbp]
\centering
\begin{threeparttable}
  \caption{Table}
  \label{}
\begin{tabular}{@{\extracolsep{5pt}} cc}
\toprule\midrule
Position & Percentage \\
\midrule
A & 5.5\% \\
B & 2.5\% \\
C & 1\% \\
D & 91\% \\
\bottomrule
\end{tabular}
\begin{tablenotes}[flushleft]\footnotesize
\item[]Notes: This is a table with text that ends up on the right side of the table.
\end{tablenotes}
\end{threeparttable}
\end{table}

\end{document} 

在此处输入图片描述

答案3

这是一个新的环境ntabular

\documentclass{article}
\usepackage{booktabs}

\newenvironment{ntabular}[1]
 {%
  \begin{lrbox}{\ntabularbox}
  \begin{tabular}[b]{#1}
 }
 {%
  \ifntabularnote
    \end{minipage}
  \else
    \end{tabular}
  \fi
  \end{lrbox}%
  \begin{tabular}{@{}c@{}}
  \usebox{\ntabularbox}\\
  \usebox{\notebox}
  \end{tabular}%
 }
\newif\ifntabularnote
\newsavebox{\ntabularbox}
\newsavebox{\notebox}
\newcommand{\ntabularnote}{%
  \end{tabular}%
  \end{lrbox}%
  \ntabularnotetrue
  \begin{lrbox}{\notebox}
  \begin{minipage}[t]{\wd\ntabularbox}
}

\begin{document}

\begin{table}[!htbp]
\centering 
\caption{Table}\label{whatever}

\medskip

\begin{ntabular}{cc}
\toprule
Position & Percentage \\
\midrule
A & 5.5\% \\ 
B & 2.5\% \\ 
C & 1\% \\ 
D & 91\% \\ 
\bottomrule
\ntabularnote
  Notes: This is a table with text that
  ends up on the right side of the table
\end{ntabular}
\end{table}

\end{document}

在此处输入图片描述

相关内容