使用表格进行顶部对齐/垂直对齐时遇到困难

使用表格进行顶部对齐/垂直对齐时遇到困难

我无法将左列的内容与表格单元格的顶部对齐。我尝试使用\begin{tabular}[t]{|l|l|},正如大多数其他帖子所建议的那样,但未能成功修复它。请帮忙。

以下是我的代码,供参考:

\documentclass{article}

\usepackage{makecell}

\begin{document}

\begin{table}
    \centering
    \begin{tabular}[t]{|l|l|}
    \hline
       \textbf{Fact Finding Heading}  &  \textbf{Stakeholder issues} \\\hline
        Materials / Supply Chain / Manufacturing  & \makecell[l]{1. \\ 2. \\ 3. \\} \\\hline
        Environment & \makecell[l]{1. \\ 2. \\ 3. \\} \\\hline
        Society & \makecell[l]{1. \\ 2. \\ 3. \\} \\\hline
        Energy & \makecell[l]{1. \\ 2. \\ } \\\hline
        Regulations & \makecell[l]{1. \\ 2. \\ } \\\hline
        Economy & \makecell[l]{1. \\ 2. \\ } \\\hline
    \end{tabular}
    \caption{Caption}
    \label{tab:my_label}
\end{table}

\end{document}

谢谢

以下是供参考的输出。(我希望左列的文本位于左上角)

使用当前代码输出(我希望左列的文本位于左上角)

答案1

这是一个常见问题,因为您需要对t右列条目进行操作对齐。可以将其视为设置单元格的锚点。下面我使用以下方法调整了美观性booktabs,但即使你最终不使用它,原理仍然是一样的:

在此处输入图片描述

\documentclass{article}

\usepackage{makecell,booktabs}

\begin{document}

\begin{tabular}{ l l }
  \toprule
  \textbf{Fact Finding Heading} & \textbf{Stakeholder issues}              \\
  \midrule
  \makecell[lt]{Materials / \\ 
    Supply Chain / \\
    Manufacturing}                         & \makecell[lt]{1. \\ 2. \\ 3.} \\
  \addlinespace
  Environment                              & \makecell[lt]{1. \\ 2. \\ 3.} \\
  \addlinespace
  Society                                  & \makecell[lt]{1. \\ 2. \\ 3.} \\
  \addlinespace
  Energy                                   & \makecell[lt]{1. \\ 2.}       \\
  \addlinespace
  Regulations                              & \makecell[lt]{1. \\ 2.}       \\
  \addlinespace
  Economy                                  & \makecell[lt]{1. \\ 2.}       \\
  \bottomrule
\end{tabular}

\end{document}

答案2

tabularx以下是使用和组合的替代booktabs方法enumitem

在此处输入图片描述

\documentclass{article}

\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{enumitem}
\newlist{tabenum}{enumerate}{1}
\setlist[tabenum]{label*=\arabic*.,
                  leftmargin=*,
                  nosep,
                  before=\begin{minipage}[t]{\hsize},
                  after=\end{minipage}}



\begin{document}

\begin{table}
    \centering
    \begin{tabularx}{\linewidth}{p{4.25cm}X}
    \toprule
       Fact Finding Heading  &  Stakeholder issues \\
    \midrule
        Materials / Supply Chain / Manufacturing  & \begin{tabenum}
                        \item A longer line of text that gets automatically broken over multiple lines.
                        \item text
                        \item text
                      \end{tabenum} \\ \addlinespace
        Environment & \begin{tabenum}
                        \item text
                        \item text
                        \item text
                      \end{tabenum}\\ \addlinespace
        Society & \begin{tabenum}
                        \item text
                        \item text
                        \item text
                      \end{tabenum} \\ \addlinespace
        Energy & \begin{tabenum}
                        \item text
                        \item text
                      \end{tabenum} \\ \addlinespace
        Regulations & \begin{tabenum}
                        \item text
                        \item text
                      \end{tabenum} \\ \addlinespace
        Economy & \begin{tabenum}
                        \item text
                        \item text
                      \end{tabenum} \\
    \bottomrule
    \end{tabularx}
    \caption{Caption}
    \label{tab:my_label}
\end{table}

\end{document}

答案3

tblr在以下环境下,一切变得简单tabularray包:您不再需要\makecell命令和makecell包。

\documentclass{article}

\usepackage{tabularray}

\begin{document}

\begin{table}
    \centering
    \begin{tblr}[t]{|l|l|}
    \hline
       \textbf{Fact Finding Heading}  &  \textbf{Stakeholder issues} \\\hline
        Materials / Supply Chain / Manufacturing  & {1. Text\\ 2. Text\\ 3. Text} \\\hline
        Environment & {1. Text\\ 2. Text\\ 3. Text} \\\hline
        Society     & {1. Text\\ 2. Text\\ 3. Text} \\\hline
        Energy      & {1. Text\\ 2. Text} \\\hline
        Regulations & {1. Text\\ 2. Text} \\\hline
        Economy     & {1. Text\\ 2. Text} \\\hline
    \end{tblr}
    \caption{Caption}
    \label{tab:my_label}
\end{table}

\end{document}

在此处输入图片描述

相关内容