我想在常规表格环境中添加一个放置选项“m”,以便将小表格放在文档的外边缘。
我可以使用以下代码“手动”实现它:
\marginpar{%
\begin{tabularx}{\marginparwidth}{X>{\centering\arraybackslash}X}%
\hline%
Dipôle & Impédance complexe \\%
\hline%
Conducteur ohmique & $R$ \\%
Condensateur & $\displaystyle{\frac{1}{\i \cdot C \cdot \omega}}$ \\%
Bobine & $\i \cdot L \cdot \omega$ \\%
\hline%
\end{tabularx}%
\captionof{table}{Impédances complexes de quelques dipôles.}%
\label{tbl:impedances}%
}%
但是当我尝试以更“自动化”的方式转置它时,它不再起作用。
我尝试过(*.sty 文件):
\RequirePackage{float}
\RequirePackage{ifthen}
\def\mparenvironment#1\end{\marginpar{\centering #1}\end}
\newboolean{mparend}%
\renewenvironment{table}[1][ht]%
{%
\ifthenelse{\equal{#1}{m}}{\setboolean{mparend}{true}}{\setboolean{mparend}{false}}%
\ifthenelse{\boolean{mparend}}{%
\let\caption\maketablemparcaption%
\mparenvironment%
}{%
\let\@makecaption\@makefloatcaption%
\@float{table}[#1]%
}%
}{%
\ifthenelse{\boolean{mparend}}{%
%
}{%
\end@float%
}%
}%
和(*.tex 文件):
\begin{table}[m]%
\begin{tabularx}{\marginparwidth}{X>{\centering\arraybackslash}X}%
\hline%
Dipôle & Impédance complexe \\%
\hline%
Conducteur ohmique & $R$ \\%
Condensateur & $\displaystyle{\frac{1}{\i \cdot C \cdot \omega}}$ \\%
Bobine & $\i \cdot L \cdot \omega$ \\%
\hline%
\end{tabularx}%
\caption{Impédances complexes de quelques dipôles.}%
\label{tbl:impedances}%
\end{table}%
我收到以下错误:
! Argument of \TX@get@body has an extra }.
<inserted text>
\par
l.314 \end
{tabularx}
! Paragraph ended before \TX@get@body was complete.
<to be read again>
\par
l.314 \end
{tabularx}
! You can't use `\vadjust' in internal vertical mode.
\sf@end@float ...ty \@floatpenalty \else \vadjust
{\penalty -\@Miv \vbox {}\...
l.314 \end
{tabularx}
! LaTeX Error: \begin{table} on input line 305 ended by \end{tabularx}.
! Missing } inserted.
<inserted text>
}
l.317 \end{table}
! LaTeX Error: Float(s) lost.
如果我用一些文本或图片替换 tabular(x) 环境,它就可以完美运行...当然,如果我使用常规放置选项(例如“ht”),它也可以运行。
有什么想法吗?提前致谢!