tabularx 中的标题对齐

tabularx 中的标题对齐

我想将表格标题从左移到右。可以吗? 在此处输入图片描述

\documentclass[a4paper]{article}
\usepackage{enumitem}
\usepackage{array}
\usepackage{multirow}
\usepackage{ltablex, booktabs}
\renewcommand{\tabularxcolumn}[1]{>{\raggedright\arraybackslash}m{#1}}
\usepackage{arydshln}
\setlength\dashlinedash{0.2pt}
\setlength\dashlinegap{1pt}
\setlength\arrayrulewidth{0.3pt}
\usepackage[tableposition=below]{caption}
\newcommand{\myhdashline}{%
\addlinespace
\hdashline
\addlinespace}
\usepackage{subfiles}
\usepackage{caption}
\usepackage{pdflscape}
\usepackage{rotating}
\usepackage{floatpag}
\usepackage{float}
\usepackage{titlesec}
\titleformat{\section}                                     
 {\normalfont\Large\bfseries}
  {\thesection.}{0.5em}{}
\titleformat{\subsection}                                   
   {\normalfont\bfseries}
  {\thesubsection.}{0.5em}{}
  \usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage[margin=1in,headsep=.15in]{geometry}
\pagestyle{fancy}
\fancyhf{}
\chead{\footnotesize Financial Disclosure Index}
\begin{document}

\begin{tabularx}{\textwidth}
{>{\hsize=1.3\hsize}X>{\hsize=0.7\hsize}X}

\textbf{Caption} \\ \midrule \endfirsthead

\textbf{Caption} \\ \midrule \endhead \bottomrule \endfoot

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\textbf{Title} & \\hline

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

TextTextTextTextTextTextText&TextTextTextTextTextTextText\\myhdashline
TextTextTextTextTextTextText & TextTextTextTextTextTextText
\\myhdashline TextTextTextTextTextTextText &
TextTextTextTextTextTextText

\end{tabularx}

\end{document}

答案1

您正在手动将标题放在表格内。如果您希望它 a) 跨越整个宽度并且 b) 右对齐,则可以使用\multicolumn。或者,您也可以简单地将真正的标题放在表格之外。

\documentclass[a4paper]{article}

\usepackage{array}
\usepackage{multirow}
\usepackage{ltablex, booktabs}
\renewcommand{\tabularxcolumn}[1]{>{\raggedright\arraybackslash}m{#1}}
\usepackage[margin=1in,headsep=.15in]{geometry}

\begin{document}

\begin{tabularx}{\textwidth}
{>{\hsize=1.3\hsize}X>{\hsize=0.7\hsize}X}

\multicolumn{2}{r}{\textbf{Caption}} \\ \midrule \endfirsthead

\textbf{Caption} \\ \midrule \endhead \bottomrule \endfoot

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\textbf{Title} & \\hline

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

TextTextTextTextTextTextText&TextTextTextTextTextTextText\\myhdashline
TextTextTextTextTextTextText & TextTextTextTextTextTextText
\\myhdashline TextTextTextTextTextTextText &
TextTextTextTextTextTextText

\end{tabularx}

\end{document}

在此处输入图片描述

相关内容