表格单元格中的水平和垂直对齐方式

And*_*lli 6 latex tabular

到目前为止,我看到的大多数迹象似乎都表明它m用于垂直居中单元格内容,但它对我不起作用。这是我所拥有的

\begin{table}[htb]
\centering

    \sffamily \begin{tabularx}{1.0\textwidth}{ m{3cm} p{5.5cm} p{5.5cm} }
    \hline
    & 
    \textbf{Helpful}
    &
    \textbf{Harmful}
    \hfill \\ \hline

    \textbf{Internal origin} \\ (organization) &
    Item 1
    ~\textbullet~ Item 2
    ~\textbullet~ Item 3
    ~\textbullet~ Item 4
    ~\textbullet~ Item 5
    ~\textbullet~ Item 6
    ~\textbullet~ Item 7
    ~\textbullet~ Item 8
    ~\textbullet~ Item 9

    &
    Item 1
    ~\textbullet~ Item 2
    ~\textbullet~ Item 3
    ~\textbullet~ Item 4
    ~\textbullet~ Item 5
    ~\textbullet~ Item 6
    ~\textbullet~ Item 7
    ~\textbullet~ Item 8
    ~\textbullet~ Item 9

    \\
    \hline
    \textbf{External origin} \\ (environment) &
    Item 1
    ~\textbullet~ Item 2
    ~\textbullet~ Item 3
    ~\textbullet~ Item 4
    ~\textbullet~ Item 5
    ~\textbullet~ Item 6
    ~\textbullet~ Item 7
    ~\textbullet~ Item 8
    ~\textbullet~ Item 9

    &
    Item 1
    ~\textbullet~ Item 2
    ~\textbullet~ Item 3
    ~\textbullet~ Item 4
    ~\textbullet~ Item 5
    ~\textbullet~ Item 6
    ~\textbullet~ Item 7
    ~\textbullet~ Item 8
    ~\textbullet~ Item 9

    \\
    \hline
    \end{tabularx} \normalfont
\caption{SWOT matrix}
\label{tab:swot-matrix}
\end{table}
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

我希望左边的单元格垂直居中,顶部的单元格水平居中。我怎样才能做到这一点?

Wer*_*ner 8

看起来很奇怪,您需要m在不想居中的列上指定一个-column。这里的动机是m-column在单元格的中间(垂直)设置锚点,就像p-column在第一行的基线设置锚点(再次,垂直)一样。因此,将第二列和第三列(垂直较高)设置为m-columns 将使它们相对于其他列垂直居中。

在此处输入图片说明

\documentclass{article}
\usepackage[margin=1cm]{geometry}% Just for this example
\usepackage{tabularx,array,booktabs}
\newenvironment{shortlist}
  {\renewcommand{\item}{\renewcommand{\item}{\unskip\space\textbullet~}}}
  {}
\renewcommand{\tabularxcolumn}[1]{m{#1}}

\begin{document}
\noindent\sffamily
\begin{tabularx}{\textwidth}{ m{3cm} X X }
  \toprule
  & \multicolumn{1}{c}{\textbf{Helpful}} & \multicolumn{1}{c}{\textbf{Harmful}} \\
  \midrule  
  \textbf{Internal origin} \\ (organization) &
  \begin{shortlist}
    \item Item 1 \item Item 2 \item Item 3 \item Item 4 \item Item 5
    \item Item 6 \item Item 7 \item Item 8 \item Item 9
  \end{shortlist}
  &
  \begin{shortlist}
    \item Item 1 \item Item 2 \item Item 3 \item Item 4 \item Item 5
    \item Item 6 \item Item 7 \item Item 8 \item Item 9
  \end{shortlist}
  \\
  \textbf{External origin} \\ (environment) &
  \begin{shortlist}
    \item Item 1 \item Item 2 \item Item 3 \item Item 4 \item Item 5
    \item Item 6 \item Item 7 \item Item 8 \item Item 9
  \end{shortlist}
  &
  \begin{shortlist}
    \item Item 1 \item Item 2 \item Item 3 \item Item 4 \item Item 5
    \item Item 6 \item Item 7 \item Item 8 \item Item 9
  \end{shortlist}
  \\
  \bottomrule
\end{tabularx}
\end{document}
Run Code Online (Sandbox Code Playgroud)

我在编码风格方面做了一些小的调整,所有这些都是为了更一致的使用和易于更改,如果这在未来发生的话。也就是说,我删除了一些硬编码\textbullet和间距的东西,并用可以全局更改的环境替换它们,如果需要的话。