3

Despite searching the forum, I still can't figure out how to control the internal cell left and right margins. In the example below, how can I tweak (e.g. reduce) the left margin for the "L-text" cells, and the right margin for the "R-text" ones? Note that defining the column widths is required. Thanks, Jorge.

Example:

\documentclass[margin=3mm]{standalone}
\usepackage{array}
\usepackage{booktabs}
\aboverulesep=0ex
\belowrulesep=0ex

\newlength{\ColWidthNormal}         \setlength{\ColWidthNormal}{1.50cm}
\newlength{\ColWidthRowHeader}      \setlength{\ColWidthRowHeader}{1.50cm}

\newlength{\RuleOffsetLeft} \setlength{\RuleOffsetLeft}{-0.4pt}
\newlength{\RuleThicknessNormal} \setlength{\RuleThicknessNormal}{1.0pt}

\newcolumntype{C}{>{\centering\arraybackslash\leavevmode}p{\ColWidthNormal}}
\newcolumntype{R}{>{\raggedleft\arraybackslash}p{\ColWidthNormal}}
\newcolumntype{L}{>{\raggedright\arraybackslash}p{\ColWidthRowHeader}}

\begin{document}
\begin{tabular}{
    |L|R|R|
}
\cmidrule[\RuleThicknessNormal](l{\RuleOffsetLeft}){2-3}
\multicolumn{1}{c|}{}& \multicolumn{1}{c|}{C-text}& \multicolumn{1}{c|}{C-text} \\
\midrule[\RuleThicknessNormal]
L-text& R-text& R-text \\
\midrule[\RuleThicknessNormal]
L-text& R-text& R-text \\
\midrule[\RuleThicknessNormal]
\end{tabular}
\end{document} 

Output:

enter image description here

Update: the solution with \hspace doesn't work below a minimum column width! Any ideas on how to solve this?

Code:

\documentclass[margin=3mm]{standalone}
\usepackage{array}
\usepackage{booktabs}
\aboverulesep=0ex
\belowrulesep=0ex

\newlength{\ColWidthNormal}         \setlength{\ColWidthNormal}{1.50cm}
%\newlength{\ColWidthRowHeader}         \setlength{\ColWidthRowHeader}{1.50cm}
\newlength{\ColWidthRowHeader}      \setlength{\ColWidthRowHeader}{1.00cm}

\newlength{\RuleOffsetLeft} \setlength{\RuleOffsetLeft}{-0.4pt}
\newlength{\RuleThicknessNormal} \setlength{\RuleThicknessNormal}{1.0pt}

\newcolumntype{C}{>{\centering\arraybackslash\leavevmode}p{\ColWidthNormal}}
\newcolumntype{R}{>{\raggedleft\arraybackslash}p{\ColWidthNormal}}
\newcolumntype{L}{>{\raggedright\arraybackslash}p{\ColWidthRowHeader}}

\begin{document}
\setlength{\tabcolsep}{3pt}
\begin{tabular}{
    |@{\hspace{0pt}}L|
    R@{\hspace{-3pt}}|
    R@{\hspace{-12pt}}|
}
\cmidrule[\RuleThicknessNormal](l{\RuleOffsetLeft}){2-3}
\multicolumn{1}{c|}{}& \multicolumn{1}{c|}{My C-text}& \multicolumn{1}{c|}{My C-text} \\
\midrule[\RuleThicknessNormal]
L-text& R-text& R-text \\
\midrule[\RuleThicknessNormal]
L-text& R-text& R-text \\
\midrule[\RuleThicknessNormal]
\end{tabular}
\end{document} 

Output:

enter image description here

1 Answer 1

3

Here is a solution with @{\hspace{some length}}:

\documentclass[margin=3mm]{standalone}

\usepackage{array}
\usepackage{booktabs}
\aboverulesep=0ex
\belowrulesep=0ex

\newlength{\ColWidthNormal} \setlength{\ColWidthNormal}{1.50cm}
\newlength{\ColWidthRowHeader} \setlength{\ColWidthRowHeader}{1.50cm}

\newlength{\RuleOffsetLeft} \setlength{\RuleOffsetLeft}{-0.4pt}
\newlength{\RuleThicknessNormal} \setlength{\RuleThicknessNormal}{1.0pt}

\newcolumntype{C}{>{\centering\arraybackslash\leavevmode}p{\ColWidthNormal}}
\newcolumntype{R}{>{\raggedleft\arraybackslash}p{\ColWidthNormal}}
\newcolumntype{L}{>{\raggedright\arraybackslash}p{\ColWidthRowHeader}}

\begin{document}

\begin{tabular}{%
    |@{\hspace{0pt}}L|R@{\hspace{1pt}}|R@{\hspace{2pt}}|
}
\cmidrule[\RuleThicknessNormal](l{\RuleOffsetLeft}){2-3}
\multicolumn{1}{c|}{}& \multicolumn{1}{c|}{C-text}& \multicolumn{1}{c|}{C-text} \\
\midrule[\RuleThicknessNormal]
L-text& R-text& R-text \\
\midrule[\RuleThicknessNormal]
L-text& R-text& R-text \\
\midrule[\RuleThicknessNormal]
\end{tabular}

\end{document} 

enter image description here

5
  • Thanks so much Bernard; this is both simple and effective! :)
    – dontpanic
    Jul 8, 2018 at 23:30
  • Bernard, for some reason the hack breaks if I reduce the column widths (see updated example)... any suggestions? :(
    – dontpanic
    Jul 8, 2018 at 23:40
  • 1
    It seems to happen because the cells aren't wide enough for the chosen margin + the default margin on the other side (6pt). If you still reduce the width, it breaks into two lines and every is aligned as wanted. You can reduce the value of \tabcolsep with \setlength{\tabcolsep}{some length} if necessary.
    – Bernard
    Jul 9, 2018 at 0:04
  • The problem with \tabcolsep is that it affects the other cells, so I cannot reduce it arbitrarily without affecting the whole table. In the updated example, I've reduced it to 3pt, and the \hspace is still unable to enforce the desired right margin :(
    – dontpanic
    Jul 9, 2018 at 0:14
  • The cell width and the cell content width are in a sort of grey zone, and I'm afraid with so small widths, each case will be a particular case and you have to do things by hand. You may, for instance, add a @{} on the left side of the problematic cell.
    – Bernard
    Jul 9, 2018 at 7:56

You must log in to answer this question.

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