乳胶填充/边缘地狱

发布于 2024-09-03 12:41:29 字数 1955 浏览 10 评论 0原文

我已经与乳胶桌搏斗太久了。我需要一个具有居中标题和包含可能环绕的文本的正文单元格的表格。由于环绕要求,我使用 p{xxx} 而不是 l 来指定单元格宽度。这导致的问题是单元格内容没有左对齐,因此看起来像间隔的垃圾。为了解决这个问题,我对每个单元格使用 \flushleft 。这确实使内容左对齐,但在单元格内容的上方和下方放置了大量空白。有没有办法阻止 \flushleft (或 \center )以停止添加大量的垂直空白?

谢谢

\begin{landscape}
    \centering
    % using p{xxx} here to wrap long text instead of overflowing it
    \begin{longtable}{ | p{4cm} || p{3cm} | p{3cm} | p{3cm} | p{3cm} | p{3cm} |}
        \hline
         & 
        % these are table headings.  the \center is causing a ton of whitespace as well
        \begin{center} \textbf{HTC HD2} \end{center} & 
        \begin{center} \textbf{Motorola Milestone} \end{center} & 
        \begin{center} \textbf{Nokia N900} \end{center} & 
        \begin{center} \textbf{RIM Blackberry Bold 9700} \end{center} &
        \begin{center} \textbf{Apple iPhone 3GS} \end{center} \\
        \hline
        \hline
        % using flushleft here to left-justify, but again it is causing a ton of white space above and below cell contents.
        \begin{flushleft}OS / Platform \end{flushleft}& 
        \begin{flushleft}Windows Mobile 6.5 \end{flushleft}& 
        \begin{flushleft}Google Android 2.1 \end{flushleft}& 
        \begin{flushleft}Maemo \end{flushleft}& 
        \begin{flushleft}Blackberry OS 5.0 \end{flushleft}& 
        \begin{flushleft}iPhone OS 3.1 \end{flushleft} \\           
        \hline

编辑:

感谢到目前为止的回答。我以为我找到了一个可行的解决方案,但这些问题仍然存在:

  • 使用 \raggedright 可以阻止长单词被连字符连接。当一个单元格包含一堆只有一个单词的行时,这看起来很糟糕。
  • 仅当以空行结束时,使用 \raggedright 才有效。这会导致每个单元格的底部都有一个完全空白的行。这是我一开始就想避免的。

     {显示} & 
        {\raggedright 4.3 英寸,800 x 400 分辨率} & 
        {\raggedright 3.7 英寸,854 x 480 分辨率} & 
        {\raggedright 3.5 英寸,800 x 480 分辨率} & 
        {\raggedright 2.44 英寸,320 x 480 分辨率} & 
        {\raggedright 3.5 英寸,480 x 320 分辨率} \\            
        \h行
    

I have been wrestling with a latex table for far too long. I need a table that has has centered headers, and body cells that contain text that may wrap around. Because of the wrap-around requirement, i'm using p{xxx} instead of l for specifying cell widths. The problem this causes is that cell contents are not left justified, so the look like spaced-out junk. To fix this problem I'm using \flushleft for each cell. This does left justify contents, but puts in a ton of white space above and below the contents of the cell. Is there a way to stop \flushleft (or \center for that matter) to stop adding copious amounts of verical whitespace?

thanks

\begin{landscape}
    \centering
    % using p{xxx} here to wrap long text instead of overflowing it
    \begin{longtable}{ | p{4cm} || p{3cm} | p{3cm} | p{3cm} | p{3cm} | p{3cm} |}
        \hline
         & 
        % these are table headings.  the \center is causing a ton of whitespace as well
        \begin{center} \textbf{HTC HD2} \end{center} & 
        \begin{center} \textbf{Motorola Milestone} \end{center} & 
        \begin{center} \textbf{Nokia N900} \end{center} & 
        \begin{center} \textbf{RIM Blackberry Bold 9700} \end{center} &
        \begin{center} \textbf{Apple iPhone 3GS} \end{center} \\
        \hline
        \hline
        % using flushleft here to left-justify, but again it is causing a ton of white space above and below cell contents.
        \begin{flushleft}OS / Platform \end{flushleft}& 
        \begin{flushleft}Windows Mobile 6.5 \end{flushleft}& 
        \begin{flushleft}Google Android 2.1 \end{flushleft}& 
        \begin{flushleft}Maemo \end{flushleft}& 
        \begin{flushleft}Blackberry OS 5.0 \end{flushleft}& 
        \begin{flushleft}iPhone OS 3.1 \end{flushleft} \\           
        \hline

Edit:

Thanks for the answers so far. I thought I found a solution that works, but these problems still exist:

  • using \raggedright stops long words from being hyphenated. This looks pretty bad when a cell contains a bunch of lines with only one word in them.
  • using \raggedright only works if you end it with a blank line. This causes every cell to have a completely blank line at the bottom of it. This was what i was trying to avoid in the first place.

        {Display} & 
        {\raggedright 4.3 inch, 800 x 400 resolution} & 
        {\raggedright 3.7 inch, 854 x 480 resolution} & 
        {\raggedright 3.5 inch, 800 x 480 resolution} & 
        {\raggedright 2.44 inch, 320 x 480 resolution} & 
        {\raggedright 3.5 inch, 480 x 320 resolution} \\            
        \hline
    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

你应该可以只指定你想要的身体细胞的格式和
仅将标题更改为以 multicolumn 居中。这样你就不会
必须像你现在一样弄乱太多的细胞。

\documentclass{article}

\begin{document}
\begin{table}
  \centering
  \begin{tabular}{l|p{2cm}|p{2cm}}
    \multicolumn{1}{c}{A} &
    \multicolumn{1}{c}{B} &
    \multicolumn{1}{c}{C} \\
    1 & {Some longer text} & {Some other text}\\
    2 & {Some longer text} & {Some other text}\\
    3 & {Some longer text} & {Some other text}\\
    4 & {Some longer text} & {Some other text}
  \end{tabular}
\end{table}
\end{document}

You should be fine to just specify how you want the body cells formated and
change only the headers to centered with multicolumn. That way you don't
have to mess with too many cells like you do right now.

\documentclass{article}

\begin{document}
\begin{table}
  \centering
  \begin{tabular}{l|p{2cm}|p{2cm}}
    \multicolumn{1}{c}{A} &
    \multicolumn{1}{c}{B} &
    \multicolumn{1}{c}{C} \\
    1 & {Some longer text} & {Some other text}\\
    2 & {Some longer text} & {Some other text}\\
    3 & {Some longer text} & {Some other text}\\
    4 & {Some longer text} & {Some other text}
  \end{tabular}
\end{table}
\end{document}
寒冷纷飞旳雪 2024-09-10 12:41:29

这不是最优雅的解决方案,但 \centering\raggedright 命令对应于 centerflushleft 环境,并且不要随着利润的增加而增加。

如果我遇到更好的解决方案,我会发布它,但我认为这可以工作。

Not the most elegant solution, but the \centering and \raggedright commands corresponds to the center and flushleft environments and don't come with the increased margins.

If I come across a nicer solution I will post it, but this could work I think.

风吹短裙飘 2024-09-10 12:41:29

以@honk的例子为基础,我想你会想要这样的:

\documentclass{article}

\begin{document}
\begin{table}
  \centering
  \begin{tabular}{>{\raggedright}l|>{\raggedright}p{2cm}|>{\raggedright}p{2cm}|}
    \multicolumn{1}{c}{A} &
    \multicolumn{1}{c}{B} &
    \multicolumn{1}{c}{C} \\
    1 & Some longer text & Some other text\\
    2 & Some longer text & Some other text\\
    3 & Some longer text & Some other text\\
    4 & Some longer text & Some other text \\
  \end{tabular}
\end{table}
\end{document}

单词仍然不会被连字符连接,但这应该可以解决你遇到的空行问题。

Building on @honk's example, i think you'd want this:

\documentclass{article}

\begin{document}
\begin{table}
  \centering
  \begin{tabular}{>{\raggedright}l|>{\raggedright}p{2cm}|>{\raggedright}p{2cm}|}
    \multicolumn{1}{c}{A} &
    \multicolumn{1}{c}{B} &
    \multicolumn{1}{c}{C} \\
    1 & Some longer text & Some other text\\
    2 & Some longer text & Some other text\\
    3 & Some longer text & Some other text\\
    4 & Some longer text & Some other text \\
  \end{tabular}
\end{table}
\end{document}

Words still won't be hyphenated, but this should solve the blank line problem you're having.

森林散布 2024-09-10 12:41:29

不要在列对齐规范中使用 p 选项,而是使用 l。然后在每个标题中使用 \hfill Somephone \hfill,并在每个正文单元中使用 \vbox to 3cm {About text}。这样做应该最大限度地减少多余的填充。

Don't use p options in the column alignment specification, but use l instead. Then in each heading, use \hfill Somephone \hfill, and in each body cell, use \vbox to 3cm {About text}. Doing so should minimise excess padding.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文