\resizebox 內的 \textwidth

\resizebox 內的 \textwidth

我想要在表格的最後一行顯示註釋,跨越所有列,使用\multicolumn{#}{p{\textwidth}}{}.這在調整大小時無法正常工作,因為textwidth保持相同的值但測量值縮小。

這是我的程式碼:

\documentclass{article}%
\usepackage{graphicx}
\begin{document}
\resizebox{\textwidth}{!}{%
\begin{tabular}{rrrrrrrrr} \hline
aaaaaaaa & aaaaaaaa & aaaaaaaa & aaaaaaaa & aaaaaaaa & aaaaaaaa & aaaaaaaa & aaaaaaaa & aaaaaaaa\\ \hline
\multicolumn{9}{p{\textwidth}}{Notes: Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et.}
\end{tabular}%
}
\end{document} 

輸出: 在此輸入影像描述

答案1

更好用threeparttablex,雖然它不完美(右邊有點太寬)

\documentclass{article}%
\usepackage{graphicx}
\usepackage[referable]{threeparttablex}
\begin{document}

\noindent
\rule{\textwidth}{1mm}

\noindent
\resizebox{\textwidth}{!}{%
  \begin{threeparttable}
    \begin{tabular}{rrrrrrrrr} \hline aaaaaaaa & aaaaaaaa & aaaaaaaa &
      aaaaaaaa & aaaaaaaa & aaaaaaaa & aaaaaaaa & aaaaaaaa &
      aaaaaaaa\\ \hline 
    \end{tabular}%
    \begin{tablenotes}
      \note Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
      sed diam nonumy eirmod tempor invidunt ut labore et.
    \end{tablenotes}
  \end{threeparttable}
}
\end{document} 

答案2

您首先需要保存/計算真實的桌子的寬度

\newsavebox\tableBox
\sbox\tableBox{\begin{tabular}{rrrr...}...\end{tabular}} % without the \multicolumn line

然後

\resizebox{\textwidth}{!}{%
  \begin{tabular}{rrrr...}
    ...
    \multicolumn{9}{p{\wd\tableBox}}{...}
  \end{tabular}%
}

完整範例:

\documentclass{article}%
\usepackage{graphicx}
\begin{document}

\newsavebox\tableBox
\sbox\tableBox{%
\begin{tabular}{rrrrrrrrr} \hline
aaaaaaaa & aaaaaaaa & aaaaaaaa & aaaaaaaa & aaaaaaaa & aaaaaaaa & aaaaaaaa & aaaaaaaa & aaaaaaaa\\ \hline
\end{tabular}%
}

\resizebox{\textwidth}{!}{%
\begin{tabular}{rrrrrrrrr} \hline
aaaaaaaa & aaaaaaaa & aaaaaaaa & aaaaaaaa & aaaaaaaa & aaaaaaaa & aaaaaaaa & aaaaaaaa & aaaaaaaa\\ \hline
\multicolumn{9}{p{\wd\tableBox}}{Notes: Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et.}
\end{tabular}%
}
\end{document} 

相關內容