1

Situation

I defined custom column types in order to manage column width and text alignment. I defined those column types as below:

\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1\linewidth}}

Issue

When using those custom column types, the sum of the width arguments cannot be equal to 1. Indeed, it does not take into account column spacing.

Question

Is there a way to subtract the tabcolsep length from the length assigned in the newcolumntype declaration?

Demo

demo

MWE

\documentclass[draft]{article}

\usepackage{mwe}
\usepackage[showframe]{geometry}
\usepackage{booktabs}
\usepackage{array}

\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1\linewidth}}

\begin{document}

% Overfull \hbox (12.0pt too wide)
\noindent
\begin{tabular}{L{1}}
  \toprule
  \lipsum[1] \\
  \bottomrule
\end{tabular}

% Manual unreliable fix
\noindent
\begin{tabular}{L{.97}}
  \toprule
  \lipsum[1] \\
  \bottomrule
\end{tabular}

\end{document}
2

You can use

p{\dimexpr#1\linewidth-2\tabcolsep\relax}
  • As simple as that. I did not know how to define an expression. Thank you. – Florian Oct 18 '17 at 16:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.