Tabularx: 自定义\hrule超出\textwidth的原因?

Tabularx: 自定义\hrule超出\textwidth的原因?

关于为什么我的自我配置超出了我的页面布局的\hrule规定,有什么想法吗?\textwidth


最小工作示例(MWE):

\documentclass{article}
\usepackage{xcolor,colortbl}
\usepackage{tabularx}

\makeatletter
    \newcommand{\thickline}{%
        \noalign {\ifnum 0=`}\fi \color{red}\hrule height 5pt
        \futurelet \reserved@a \@xhline
    }
\makeatother

\begin{document}
\begin{tabularx}{\textwidth}{ll}
    test & test \\\thickline
    test & test \\
\end{tabularx}
\end{document}

答案1

article,如果您没有另行定义,则以缩进开始段落(例外情况是紧接在章节标题之后的段落)。 可以通过以下方式删除:

  • 在环境\noindent之前立即添加tabularx
  • 将环境封闭tabularx在浮动环境中table
  • 将其封闭在center环境中

    \documentclass{article}
    \usepackage[table]{xcolor} % loads 'colortbl' automatically
    \usepackage{tabularx}
    
    \makeatletter
        \newcommand{\thickline}{%
            \noalign {\ifnum 0=`}\fi \color{red}\hrule height 5pt
            \futurelet \reserved@a \@xhline
        }
    \makeatother
    
    %---------------- show page layout. don't use in a real document!
    \usepackage{showframe}
    \renewcommand\ShowFrameLinethickness{0.15pt}
    \renewcommand*\ShowFrameColor{\color{red}}
    %---------------------------------------------------------------%
    
    \begin{document}
    \section{Tests}
    \begin{tabularx}{\textwidth}{lX}
        test & test \\\thickline
        test & test \\
    \end{tabularx}
    
    \noindent
    \begin{tabularx}{\textwidth}{lX}
        test & test \\\thickline
        test & test \\
    \end{tabularx}
    
    \bigskip
    or
    
    \begin{table}[htb]
    \begin{tabularx}{\textwidth}{lX}
        test & test \\\thickline
        test & test \\
    \end{tabularx}
    \end{table}
    
    or
    
    \begin{center}
    \begin{tabularx}{\textwidth}{lX}
        test & test \\\thickline
        test & test \\
    \end{tabularx}
    \end{center}
    
    \end{document}
    

在此处输入图片描述

相关内容