1

Any ideas on why my self configured \hrule exceeds the specified \textwidth of my page layout?


Minimum Working Example (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}
3
  • 3
    because your table not star at left text border but it is indented. put \noindent before it or put your table in table environment.
    – Zarko
    Commented Aug 22, 2018 at 21:27
  • 1
    @Zarko: Please post this as an answer - awesome! :-) Thank you very much!
    – Dave
    Commented Aug 22, 2018 at 22:08
  • 3
    Unrelated: load xcolor with option [table]: it will load colortbl and add further commands, such as\rowcolors.
    – Bernard
    Commented Aug 22, 2018 at 22:08

1 Answer 1

3

article, if you do not define otherwise, starts paragraphs with some indentation (exceptions are paragraphs immediately after sections' titles). It can be removed by:

  • adding \noindent immediately before the tabularx environment
  • enclosing the tabularx environment in float environment table
  • enclosing it in a center environmemt

    \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}
    

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .