表格单元格溢出

表格单元格溢出

考虑这个文档示例:

\documentclass[a4paper,draft]{article}

\usepackage{calc}
\usepackage[demo]{graphicx}
\usepackage{tabularx,multirow}

\usepackage{geometry}
\geometry{hmargin=0cm}

\newlength\framewidth
\setlength{\framewidth}{\paperwidth}
\addtolength{\framewidth}{-3cm}

\begin{document}
\centering

\fbox{
\begin{tabularx}{\framewidth}{XXX}
\multirow{3}{0.30\framewidth}{\centering
\includegraphics[width=0.2\textwidth, height=1cm]{test}\vspace{0.1cm}\linebreak\sffamily\tiny
subtext\linebreak
more text} &%
\multirow{3}{0.30\framewidth}{\centering\large\textsc{Project name}\linebreak\textbf{Current document, more text, and even more text, still more text}} &%
a \\
& & b \\
& & c \\
\end{tabularx}
}
\end{document}

我用黄色标记了超出单元格的文本。另外,如果我把所有内容都放在一个框中,然后测量该框,它会比框中包含的实际文本短。这是为什么?

溢出表格单元格

答案1

您为此单元格使用了\multirow{3}{...},因此明确请求了三行,但您有足够四行的文本。请将其更改为\multirow{4}{...}并添加 ,\\或将列类型更改为p{.3\framewidth}

请注意,据我所知,\multirow内容的官方高度仅为第一行,其余部分则是深度

另请参阅问题的答案“为什么 \parbox 的 \settoheight 不起作用?”“测量固定宽度文本框的高度”解释了如何测量此类盒子的正确高度。


回应原始发帖人的评论:

您可以将这三列都定义为p类型列,并像其他列一样将右侧内容输入为一个单元格。您可以使用\newline换行符命令:

\documentclass[a4paper,draft]{article}

\usepackage{calc}
\usepackage{graphicx}
\usepackage{tabularx,multirow}

\usepackage{geometry}
\geometry{hmargin=0cm}

\newlength\framewidth
\setlength{\framewidth}{\paperwidth}
\addtolength{\framewidth}{-3cm}

\begin{document}
\centering

\fbox{%
\begin{tabularx}{\framewidth}{p{.3\framewidth}p{.3\framewidth}p{.3\framewidth}}
 \multirow{3}{0.30\framewidth}{%
   \centering
   %\includegraphics[width=0.2\textwidth]{Images/Logo}%
   \rule{.2\textwidth}{1cm}
   \vspace{0.1cm}\linebreak\sffamily\tiny
   subtext\linebreak
   more text} &%
   \centering\large\textsc{Project name}\linebreak\textbf{Current document, more text, and even more text, still more text}
  &%
  { a \newline b \newline c \newline } \\
\end{tabularx}%
}
\end{document}

我认为tabular在这种情况下,环境可能不是最好的选择。三个minipages并排放置会更合适:

\documentclass[a4paper]{article}
\usepackage{graphicx}
\usepackage{tabularx}
\usepackage{calc}


\newlength\framewidth
\setlength{\framewidth}{\textwidth-4\tabcolsep-2\fboxsep}

\begin{document}
\centering

% Horizontal rule for comparison
\hrule\par\bigskip

\fbox{%
\begin{minipage}[t]{.333\framewidth}
   \centering
   \vspace*{0pt}
   %\includegraphics[width=0.2\textwidth]{Images/Logo}%
   \rule{.8\textwidth}{1cm}% graphic dummy
   \\[.1cm]\sffamily\tiny
   subtext\linebreak
   more text
\end{minipage}%
\hspace{2\tabcolsep}%
\begin{minipage}[t]{.333\framewidth}
   \centering\large\textsc{Project name}\\
   \bfseries Current document, more text, and even more text,
   still more text
\end{minipage}%
\hspace{2\tabcolsep}%
\begin{minipage}[t]{.333\framewidth}
   a \\ b \\ c
\end{minipage}%
}
\end{document}

相关内容