如何在日志文件中写入表格宽度?例如,假设我有 2 个表格——当我编译 tex 文件时,我想在日志文件中写入宽度/广度。是否可以通过宏或定义来实现,因为我需要在自己的模板中使用它,而不是在文件中
\documentclass[twocolumn]{article}
\usepackage{showframe}
\begin{document}
\begin{table}[ht]
\caption{Nonlinear Model Results}
\begin{tabular}{c c c c}
\hline
Case & Method
\#1 & Method
\#2 & Method
\#3\\
\hline
1 & 50 & Sample Piece & 970\\
2 & 47 & Sample Piece & 230\\
\hline
\end{tabular}
\end{table}
\begin{table}[ht]
\caption{Nonlinear Model Results}
\begin{tabular}{c c c c}
\hline
Case & Method
\#1 & Method
\#2 & Method
\#3\\
\hline
1 & 50 & Sample Piecedgjgh aweg & 970\\
2 & 47 & Sample Piece & 230\\
\hline
\end{tabular}
\end{table}
\end{document}
答案1
这无法测量标题宽度...只能测量宽度tabular
。它的工作原理是将放置tabular
在临时框中,然后使用\typeout
将宽度打印到日志文件中。
已编辑,将其放置在其自己的环境中mtabular
(测量表格)。此外,mtabular
现在有一个可选参数,用作 ID,如果默认使用\thetable
不合适(取决于使用情况)。
\documentclass[twocolumn]{article}
\usepackage{showframe,environ}
\newenvironment{mtabular}[2][\thetable]{%
\gdef\savemtabopt{#1}%
\setbox0=\hbox\bgroup\begin{tabular}{#2}}{\end{tabular}\egroup\copy0
\typeout{Table \savemtabopt. width is \the\wd0.}%
}
\begin{document}
\begin{table}[ht]
\caption{Nonlinear Model Results}
\begin{mtabular}{c c c c}
\hline
Case & Method
\#1 & Method
\#2 & Method
\#3\\
\hline
1 & 50 & Sample Piece & 970\\
2 & 47 & Sample Piece & 230\\
\hline
\end{mtabular}%
\end{table}
\begin{table}[ht]
\caption{Nonlinear Model Results}
\begin{mtabular}{c c c c}
\hline
Case & Method
\#1 & Method
\#2 & Method
\#3\\
\hline
1 & 50 & Sample Piecedgjgh aweg & 970\\
2 & 47 & Sample Piece & 230\\
\hline
\end{mtabular}
\end{table}
\end{document}