使用 makecell 进行悬挂缩进

使用 makecell 进行悬挂缩进

我在用着\usepackage{makecell}来拆分表格中的长文本。我想为该单元格添加悬挂缩进。我看到了一些关于自定义此类方面的文档,但修改它以满足此需求超出了我的能力范围。感谢您的帮助。

\begin{table}[]
\centering
\caption{My caption}
\label{my-label}
\begin{tabular}{lc}
\multicolumn{1}{c}{\textbf{Header}}                                        & \multicolumn{1}{r}{\textbf{Header}} \\
\makecell[l]{Some really long text\\ which I would like\\ to break up\\ with a hanging indent} & Short Text                         
\end{tabular}
\end{table}

编辑:

在此处的 makecell 文档中(从第 9 页开始),您将看到各种对齐选项,包括缩进第一行http://ctan.mirrors.hoobly.com/macros/latex/contrib/makecell/makecell.pdf。但是,我想要一个悬挂缩进,如下所示。我知道我可以为每行添加强制间距,但有没有更紧凑的方法?

在此处输入图片描述

答案1

如果我理解了您所说的悬挂缩进的含义,我认为它无法在 内完成makecell,这是为标准rlc单元格完成的。但是,您可以使用单元格轻松获得它p{some length}。我借此机会使用命令简化了列标题的代码\thead,并使用包在标题和表格之间留出了更好的间距caption

\documentclass{article}
\usepackage{array, tabularx, caption, makecell}
\renewcommand\theadfont{\normalsize\bfseries}
\usepackage{amsmath}

\begin{document}

\begin{table}[!htb]
  \centering
  \caption{My caption}
  \label{my-label}
  \begin{tabular}{>{\hangindent=1.5em\hangafter=1}p{4cm}c}
    \thead{Header} & \thead{Header} \\
    Some really long text\newline which I would like\newline to break up\newline with a hanging indent & Short Text
  \end{tabular}
\end{table}

\end{document} 

在此处输入图片描述

答案2

可以\makecell按照文档执行此操作:

\begin{tabularx}{\textwidth}{XXX}
  Hello
  & \makecell[{{>{\hangindent1em}X}}]{A very long strng of text which really should be broken at some point hopefully, and should be hung-indented.}
  & World
\end{tabularx}

您甚至可以更进一步,定义自定义列类型:

% in preamble
\newcolumntype{I}{>{\hangindent1em}X}

% ...

% in document body
\begin{tabularx}{\textwidth}{XXX}
  Hello
  & \makecell[{I}]{A very long strng of text which really should be broken at some point hopefully, and should be hung-indented.}
  & World
\end{tabularx}

相关内容