在表格内对齐段落

在表格内对齐段落

考虑以下代码:

\documentclass{article}

\begin{document}

\begin{tabular}{|p{5cm}|}
  \hline
  \textbf{item 1:} These are some texts to just fill in the first line.
   \tabularnewline
   this is the second Item which still needs to be indented
   \begin{itemize}
    \item item 1
\item item 2
   \end{itemize}
 \\ \hline 
\end{tabular}

\end{document}

运行此程序后,您将得到一个只有一个单元格的表格。我的问题是

如何对齐表格中的段落行(第一行除外),使其从指定边距开始?换句话说,如何让段落除第一行外的每一行都缩进(例如缩进 1 厘米)?

如果这很重要,我的实际代码有p{\textwidth}。顺便说一句,我在单元格中有一个我想保留的项目。
请考虑我使用的是从右到左的语言(使用了 bidi 包),静态向左侧添加边距的解决方案没有用。实际上,我需要文本右侧部分的间距,而不是左侧的间距。

答案1

由于技术原因(或者说 XeTeX 的双向排版 bug),你需要将类似列表的环境放在 \parbox 或 minipage 环境中。因此解决方案是:

\documentclass{article}
\usepackage{bidi}
\setRTL
\begin{document}

\begin{tabular}{|p{5cm}|}
  \hline
  \textbf{item 1:} These are some texts to just fill in the first line.
   \tabularnewline
   this is the second Item which still needs to be indented
\parbox{5cm}{\leavevmode%
   \begin{itemize}
    \item item 1
\item item 2
   \end{itemize}}
 \\ \hline 
\end{tabular}

\end{document}

或者

\documentclass{article}
\usepackage{bidi}
\setRTL
\begin{document}

\begin{tabular}{|p{5cm}|}
  \hline
  \textbf{item 1:} These are some texts to just fill in the first line.
   \tabularnewline
   this is the second Item which still needs to be indented
\begin{minipage}{5cm}
   \begin{itemize}
    \item item 1
\item item 2
   \end{itemize}
\end{minipage}
 \\ \hline 
\end{tabular}

\end{document}

答案2

  • 第一行显示只有第一行被推到右边

  • 第二行显示除第一行之外的所有行都被推到右边

替代文本

\documentclass{article}

\usepackage[margin=2cm,a4paper]{geometry}

\usepackage{lipsum}

\usepackage{longtable,array,calc}

\newcommand{\dummy}{%
This is my favourite table definition. 
It is very powerful to solve many problems in \LaTeX.
The quick brown dog jumps over the lazy fox.
}

\newcolumntype{A}[1]%
    {%
        >{%
            \begin{minipage}%
            {%
                    #1%
            }%
            \vspace{\tabcolsep}%
         }%
        c%
        <{%
                \vspace{\tabcolsep}%
                \end{minipage}%
         }%
    }%

\newenvironment{First}[1][1cm]
{\hspace{#1}\ignorespaces}
{}

\newenvironment{Complement}[1][1cm]
{\hspace{#1}\begin{minipage}{\linewidth-#1}\hspace{-#1}\ignorespaces}
{\end{minipage}}


\begin{document}

\begin{longtable}{|A{10cm}|}\hline%
 \begin{First}
 \dummy
 \end{First}
 \tabularnewline\hline 
 %============================================
 \begin{Complement}
 \dummy%
 \end{Complement}
 \tabularnewline\hline
\end{longtable}

\end{document}

答案3

您是否在寻找类似这样的事物?:

\documentclass[a5paper]{article}
\usepackage{tabularx}
\begin{document}
\begin{tabularx}{\textwidth}{|>{\bfseries}lX|}
  \hline
  Item 1:& These are some texts 
  just to fill in the first line. 
  And some more texts 
  just to fill in the second line.\\
  Item 2:& These are some texts 
  just to fill in the first line. 
  And some more texts 
  just to fill in the second line.
 \\ \hline 
\end{tabularx}
\end{document}​

根据问题的更多细节进行更新:

\documentclass[a5paper]{article}
\usepackage{tabularx}
\begin{document}
\begin{tabularx}{\textwidth}{|>{\bfseries}lX|}
  \hline
  Item 1:& These are some texts 
  just to fill in the first line. 
  And some more texts 
  just to fill in the second line.\\
  & This is the second Item which still needs to be indented
\begin{itemize}
\item item 1
\item item 2
\end{itemize}
\\ \hline 
\end{tabularx}
\end{document}​

请注意:(a) 我将主要项目存根设为表格中的单独一列(抱歉,我不知道 tabularx 如何处理 RTL 文本);(b) 而不是\tabularnewline,我为第二位添加了一个表格行。虽然这可能在语法上不符合您的要求,但我认为它可能会使事情更易于维护。


这就是我猜RTL 可能会起作用:

\documentclass[a5paper]{article}
\usepackage{tabularx}
\begin{document}
\begin{tabularx}{\textwidth}{|X>{\bfseries}l|}
  \hline
 These are some texts & Item 1: 
  just to fill in the first line. 
  And some more texts 
  just to fill in the second line.\\
  This is the second Item which still needs to be indented
\begin{itemize}
\item item 1
\item item 2
\end{itemize}
\\ \hline 
\end{tabularx}
\end{document}​

答案4

\documentclass{article}
\usepackage{array,paralist}
\begin{document}

\begin{tabular}{|p{5cm}|}  \hline
\begin{compactdesc}
 \item[item 1:] These are some texts to just fill in the first line.
 \item[item 2:] These are some texts to just fill in the first line.
\end{compactdesc}\\\hline
A line after the description environment\\
\hline 
\end{tabular}

\end{document}

相关内容