如何将表格单元格右对齐并居中?

如何将表格单元格右对齐并居中?

我按照以下回答中的建议,将一列标题垂直居中这个帖子使用arraym{}。我怎样才能右对齐这些标题?

以下是我当前的表格和结果的图片:

在此处输入图片描述

\documentclass[a4paper]{article}

\usepackage[demo]{graphicx}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{array}

\begin{document}

\begin{figure}\centering%
    \def\tinySubWidth{2.5cm}
    \begin{tabular}{m{2cm}m{\tinySubWidth}m{\tinySubWidth}m{\tinySubWidth}m{\tinySubWidth}}
        &
        \centering Column 1&
        \centering Column 2&
        \centering Column 3&
        Column 4
        \\
        The first row heading%
        &\includegraphics[width=\tinySubWidth]{path}%
        &\includegraphics[width=\tinySubWidth]{path}%
        &\includegraphics[width=\tinySubWidth]{path}%
        &\includegraphics[width=\tinySubWidth]{path}\\
        The second row heading%
        &\includegraphics[width=\tinySubWidth]{path}%
        &\includegraphics[width=\tinySubWidth]{path}%
        &\includegraphics[width=\tinySubWidth]{path}%
        &\includegraphics[width=\tinySubWidth]{path}\\
        The third row heading%
        &\includegraphics[width=\tinySubWidth]{path}%
        &\includegraphics[width=\tinySubWidth]{path}%
        &\includegraphics[width=\tinySubWidth]{path}%
        &\includegraphics[width=\tinySubWidth]{path}\\
        The fourth row heading%
        &\includegraphics[width=\tinySubWidth]{path}%
        &\includegraphics[width=\tinySubWidth]{path}%
        &\includegraphics[width=\tinySubWidth]{path}%
        &\includegraphics[width=\tinySubWidth]{path}\\
    \end{tabular}
    \caption{Bla}
    \label{fig:res-axvel-latax}
\end{figure}

\end{document}

答案1

您可以使用以下>{...}语法将列设置为\raggedleft(或者\RaggedLeft如果ragged2e包已加载):

\documentclass[a4paper]{article}

\usepackage[demo]{graphicx}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{array}

\begin{document}

\begin{figure}\centering%
    \def\tinySubWidth{2.5cm}
    \begin{tabular}{>{\raggedleft}m{2cm}m{\tinySubWidth}m{\tinySubWidth}m{\tinySubWidth}m{\tinySubWidth}}
        &
        \centering Column 1&
        \centering Column 2&
        \centering Column 3&
        Column 4
        \\
        The first row heading%
        &\includegraphics[width=\tinySubWidth]{path}%
        &\includegraphics[width=\tinySubWidth]{path}%
        &\includegraphics[width=\tinySubWidth]{path}%
        &\includegraphics[width=\tinySubWidth]{path}\\
        The second row heading%
        &\includegraphics[width=\tinySubWidth]{path}%
        &\includegraphics[width=\tinySubWidth]{path}%
        &\includegraphics[width=\tinySubWidth]{path}%
        &\includegraphics[width=\tinySubWidth]{path}\\
        The third row heading%
        &\includegraphics[width=\tinySubWidth]{path}%
        &\includegraphics[width=\tinySubWidth]{path}%
        &\includegraphics[width=\tinySubWidth]{path}%
        &\includegraphics[width=\tinySubWidth]{path}\\
        The fourth row heading%
        &\includegraphics[width=\tinySubWidth]{path}%
        &\includegraphics[width=\tinySubWidth]{path}%
        &\includegraphics[width=\tinySubWidth]{path}%
        &\includegraphics[width=\tinySubWidth]{path}\\
    \end{tabular}
    \caption{Bla}
    \label{fig:res-axvel-latax}
\end{figure}

\end{document}

在此处输入图片描述

相关内容