设想
请看下面的截图。上面的表格是使用minipage
类型列生成的,下面的表格是使用 生成的m{}
。
没有使用\fboxsep
方法(已经回答这里),如何修改底部表格,使其看起来像顶部表格?
截屏
最少代码
\documentclass{article}
\usepackage{array,calc,longtable}
\tabcolsep=5mm
\arrayrulewidth=2pt
\newcolumntype{A}
{
>{\begin{minipage}{0.3\linewidth-2\tabcolsep-1.5\arrayrulewidth}%
\vspace{\tabcolsep}\centering}%
c%
<{\vspace{\tabcolsep}\end{minipage}}%
}
\newcolumntype{B}
{
@{}>{\centering}%
m{0.3\linewidth-0\tabcolsep-1.5\arrayrulewidth}%
<{}@{}%
}
\def\pic{\rule{2.5cm}{1cm}}
\begin{document}
\begin{longtable}{|*2{A|}}\hline
\pic & \pic \tabularnewline\hline
\end{longtable}
\begin{longtable}{|*2{B|}}\hline
\pic & \pic \tabularnewline\hline
\end{longtable}
\end{document}
答案1
\documentclass{article}
\usepackage{array,calc,longtable,varwidth}
\tabcolsep=5mm
\arrayrulewidth=2pt
\newcolumntype{A}
{
>{\begin{minipage}{0.3\linewidth-2\tabcolsep-1.5\arrayrulewidth}%
\vspace{\tabcolsep}\centering}%
c%
<{\vspace{\tabcolsep}\end{minipage}}%
}
\newsavebox\TBox
\newlength\THeight
\newlength\TWidth
\newenvironment{saveTBox}[1][0.5\linewidth]
{\begin{lrbox}{\TBox}\varwidth{#1}}
{\endvarwidth\end{lrbox}%
\THeight=\ht\TBox \advance\THeight by \dp\TBox \advance\THeight by 30pt
\TWidth=\wd\TBox\advance\TWidth by 30pt
\minipage[c][\THeight][c]{\TWidth}\centerline{\usebox\TBox}\endminipage}
\newcolumntype{B}{@{}>{\saveTBox}c<{\endsaveTBox}@{}}
\def\pic{\rule{2.5cm}{1cm}}
\begin{document}
\begin{longtable}{|*2{A|}}\hline
\pic & \pic \tabularnewline\hline
\end{longtable}
\begin{longtable}{|*2{B|}}\hline
\pic & \pic \tabularnewline\hline
\end{longtable}
\end{document}