5

I want to create a column spanning 5 columns with m column specifier. It seems my calculation \multicolumn{5}{m{5\temp}|}{\hrulefill} is wrong as the rule does not occupy the left space. What is the correct calculation?

\documentclass[12pt]{article}
\usepackage[a6paper,landscape,left=3mm,right=3mm,top=3mm,bottom=12mm]{geometry}
\usepackage{longtable,array}

\tabcolsep=1mm\relax
\arrayrulewidth=1pt\relax
\renewcommand*{\arraystretch}{2.5}
\newlength\temp
\temp=\dimexpr\dimexpr\textwidth-7\arrayrulewidth-12\tabcolsep\relax/6\relax

\begin{document}
\begin{longtable}{|*{6}{m{\temp}|}}\hline
1 & 2 & 3 & 4 & 5 & 6 \\\hline
\LaTeX &\multicolumn{5}{m{5\temp}|}{\hrulefill}\\\hline
\end{longtable}
\end{document}

enter image description here

6

No calculation necessary:

\documentclass[12pt]{article}
\usepackage[a6paper,landscape,left=3mm,right=3mm,top=3mm,bottom=12mm]{geometry}
\usepackage{longtable,array}

\tabcolsep=1mm\relax
\arrayrulewidth=1pt\relax
\renewcommand*{\arraystretch}{2.5}
\newlength\temp
\temp=\dimexpr\dimexpr\textwidth-7\arrayrulewidth-12\tabcolsep\relax/6\relax

\begin{document}

\begin{longtable}{|*{6}{m{\temp}|}}\hline
1 & 2 & 3 & 4 & 5 & 6 \\\hline
\LaTeX &\multicolumn{5}{@{}c@{}|}{\hrulefill}\\\hline
\end{longtable}

\end{document}

enter image description here

2

For the table you're creating, no (human) calculations of any kind are required: Just (a) employ a tabularx environment instead of a tabular environment and (b) the c column type for the cell that spans multiple columns of type X.

\documentclass[12pt]{article}
\usepackage[a6paper,landscape,hmargin=3mm,top=3mm,bottom=12mm]{geometry}
\usepackage{tabularx}
\renewcommand{\tabularxcolumn}[1]{m{#1}} % use "m" rather than "p" raw column type

\setlength\tabcolsep{1mm}         % default value: 6pt=2.11mm
\setlength{\arrayrulewidth}{1pt}  % default value: 0.4pt
\renewcommand*{\arraystretch}{2.5}

\begin{document}

\noindent
\begin{tabularx}{\textwidth}{|*{6}{X|}} \hline
1 & 2 & 3 & 4 & 5 & 6 \\ \hline
\LaTeX &\multicolumn{5}{@{}c@{}|}{\hrulefill}\\ \hline
\end{tabularx}

\end{document}
0

I found the solution:

\multicolumn{5}{m{\dimexpr\textwidth-\temp-3\arrayrulewidth-4\tabcolsep\relax}|}{\hrulefill}

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.