垂直居中文本宽度表

垂直居中文本宽度表

抱歉,我刚开始使用 LaTeX。我有一张表格,其宽度设置为\textwidth使用tabularx{\textwidth},其中一行将有 3 或 4 行。这是我当前的代码:

\renewcommand{\arraystretch}{1.2}
    \arrayrulecolor{gray}
    \begin{table}[b!] % hbtp
        \centering
        \begin{tabularx}{\textwidth}{ c | c | X }
            \arrayrulecolor{black} 
            \hline
            \textbf{$e_\#$} & \textbf{Time interval} & \textbf{Topic} \\ 
            \hline
            \arrayrulecolor{gray}
            1 & \makecell{From: 2019-04-15 20:30:05 \\ To: 2019-04-15 21:30:05} & \textbf{díamundialdelarte, 15deabril:} enfocat(0.94), meningitis(0.94), construyendolarepública(0.94), 14deabril(0.68), ley(0.66), españa(0.62)  \\
            \hline
            2 & \makecell{From: 2019-04-15 09:00:05 \\ To: 2019-04-15 17:00:05} & \textbf{gracias:} semana(0.61), muchísimas(0.64) \\
            \hline
            3 & \makecell{From: 2019-04-15 19:30:05 \\ To: 2019-04-16 01:00:05} & \textbf{notre:} dame(0.98), catedral(0.92), incendio(0.76), parís(0.91), historia(0.73), humanidad(0.77), llamas(0.74), paris(0.64), tristeza(0.65)  \\
            \hline
        \end{tabularx}
        \caption{April 15th 2019 top 3 events}
        \label{tab:mabed-impact}
    \end{table}
    \arrayrulecolor{black}
    \renewcommand{\arraystretch}{1.5}

它的可视化效果如下:

表格可视化

我希望:

  • 所有单元格都垂直居中
  • 第 1 列和第 2 列水平居中
  • 第 3 列水平左对齐,但其标题(第 1 行)水平居中

如何实现这一点?

更新:

\begin{table}[hbtp]
        \centering
        \renewcommand{\tabularxcolumn}[1]{m{#1}}
        \begin{tabularx}{\textwidth}{ c c >{\RaggedRight}X }
            \toprule
            \textbf{$e_\#$} & \textbf{Time interval} & \makecell[cc]{\textbf{Topic}} \\ 
            \midrule
            1 & \begin{tabular}[t]{r@{:~}l} From & 2019-04-15 20:30:05 \\ To & 2019-04-15 21:30:05\end{tabular} & \textbf{díamundialdelarte, 15deabril:} enfocat(0.94), meningitis(0.94), construyendolarepública(0.94), 14deabril(0.68), ley(0.66), españa(0.62)  \\\addlinespace

            2 & \begin{tabular}[t]{r@{:~}l}From& 2019-04-15 09:00:05 \\ To & 2019-04-15 17:00:05\end{tabular} & \textbf{gracias:} semana(0.61), muchísimas(0.64) \\ \addlinespace
            3 & \begin{tabular}[t]{r@{:~}l}From & 2019-04-15 19:30:05 \\ To & 2019-04-16 01:00:05 \end{tabular} & \textbf{notre:} dame(0.98), catedral(0.92), incendio(0.76), parís(0.91), historia(0.73), humanidad(0.77), llamas(0.74), paris(0.64), tristeza(0.65)  \\
            \bottomrule
        \end{tabularx}
        \caption{April 15th 2019 top 3 events}
        \label{tab:mabed-impact}
    \end{table}

更新

答案1

您可以tabularx X使用 将类型列重新定义为垂直居中\renewcommand{\tabularxcolumn}[1]{m{#1}}。使用makecelll您已经使用的包,您还可以更改单个单元格的水平(和垂直)对齐方式。结合这些,您可以实现以下结果:

在此处输入图片描述

\documentclass{article}
\usepackage{geometry}
\usepackage{tabularx}
\usepackage{makecell}
\usepackage[table]{xcolor}
\usepackage{array}
\renewcommand{\tabularxcolumn}[1]{m{#1}}
\begin{document}


    \begin{table}
    \renewcommand{\arraystretch}{1.2}
    \arrayrulecolor{gray}
        \centering
        \begin{tabularx}{\textwidth}{ c | c | X }
            \arrayrulecolor{black} 
            \hline
            \textbf{$e_\#$} & \textbf{Time interval} & \makecell[cc]{\textbf{Topic}} \\ 
            \hline
            \arrayrulecolor{gray}
            1 & \makecell{From: 2019-04-15 20:30:05 \\ To: 2019-04-15 21:30:05} & \textbf{díamundialdelarte, 15deabril:} enfocat(0.94), meningitis(0.94), construyendolarepública(0.94), 14deabril(0.68), ley(0.66), españa(0.62)  \\
            \hline
            2 & \makecell{From: 2019-04-15 09:00:05 \\ To: 2019-04-15 17:00:05} & \textbf{gracias:} semana(0.61), muchísimas(0.64) \\
            \hline
            3 & \makecell{From: 2019-04-15 19:30:05 \\ To: 2019-04-16 01:00:05} & \textbf{notre:} dame(0.98), catedral(0.92), incendio(0.76), parís(0.91), historia(0.73), humanidad(0.77), llamas(0.74), paris(0.64), tristeza(0.65)  \\
            \hline
        \end{tabularx}
        \caption{April 15th 2019 top 3 events}
        \label{tab:mabed-impact}
    \end{table}


    \end{document}

就我个人而言,我建议采用略有不同的设计(少一些水平线,没有垂直线,:在第二列对齐):

在此处输入图片描述

\documentclass{article}
\usepackage{geometry}
\usepackage{tabularx}
\usepackage{makecell}
\usepackage{array}


\usepackage{booktabs}
\begin{document}

    \begin{table}
        \centering
        \begin{tabularx}{\textwidth}{ c  c  X }
            \toprule
            \textbf{$e_\#$} & \textbf{Time interval} & \makecell[cc]{\textbf{Topic}} \\ 
            \midrule
            1 & \begin{tabular}[t]{r@{:~}l} From & 2019-04-15 20:30:05 \\ To & 2019-04-15 21:30:05\end{tabular} & \textbf{díamundialdelarte, 15deabril:} enfocat(0.94), meningitis(0.94), construyendolarepública(0.94), 14deabril(0.68), ley(0.66), españa(0.62)  \\\addlinespace

            2 & \begin{tabular}[t]{r@{:~}l}From& 2019-04-15 09:00:05 \\ To & 2019-04-15 17:00:05\end{tabular} & \textbf{gracias:} semana(0.61), muchísimas(0.64) \\ \addlinespace
            3 & \begin{tabular}[t]{r@{:~}l}From & 2019-04-15 19:30:05 \\ To & 2019-04-16 01:00:05 \end{tabular} & \textbf{notre:} dame(0.98), catedral(0.92), incendio(0.76), parís(0.91), historia(0.73), humanidad(0.77), llamas(0.74), paris(0.64), tristeza(0.65)  \\
            \bottomrule
        \end{tabularx}
        \caption{April 15th 2019 top 3 events}
        \label{tab:mabed-impact}
    \end{table}


\end{document}

最后,文中似乎缺少一些空格。真的只有一个词díamundialdelarte吗?construyendolarepública

相关内容