【问题标题】:latex padding / margin hell乳胶填充/边距地狱
【发布时间】:2010-05-29 15:33:16
【问题描述】:

我与乳胶桌搏斗太久了。我需要一个具有居中标题的表格,以及包含可能环绕的文本的正文单元格。由于环绕要求,我使用 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 才有效。这会导致每个单元格的底部都有一个完全空白的行。这是我一开始就试图避免的。

        {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
    

【问题讨论】:

    标签: latex padding margin


    【解决方案1】:

    您应该只指定您希望体细胞如何形成和 仅将标题更改为以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}
    

    【讨论】:

    • 我正在考虑(一种变体)这种方法,但不确定它是否可行。感谢您清除此问题。这肯定是比我的更优雅的解决方案。
    【解决方案2】:

    不是最优雅的解决方案,但 \centering\raggedright 命令对应于 centerflushleft 环境,并且不会增加边距。

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

    【讨论】:

    • 你能发一个sn-p来展示如何使用roughright吗?其他人也提出了建议,但我没有运气让它发挥作用。它是否需要在环境中或其他东西中?感谢您的帮助
    • 很好,我得到了这个与 raggedright 一起工作。令人难以置信的是,我不得不在每个文本字符串之后添加一个额外的空白行,并用 {} 包装所有内容......哦,乳胶。
    【解决方案3】:

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

    \documentclass{文章}

    \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}
    

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

    【讨论】:

      【解决方案4】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-04-17
        • 1970-01-01
        • 2012-04-02
        • 2012-07-27
        • 2011-07-18
        • 2015-02-15
        • 1970-01-01
        相关资源
        最近更新 更多