3

I want to do a calculation inside tabular environment, My tabular look like this

\documentclass{book} 
\usepackage{array}
\usepackage{fp}
\begin{document}
\begin{tabular}{|*{4}{c|}}
\hline
a & b & c & d  \\
\hline
\multicolumn{3}{|c|}{a} & b \\
\hline
\multicolumn{2}{|>{\centering\arraybackslash}p{0.5\textwidth}|}{a} & b & c\\
\hline
\end{tabular}
\end{document}

enter image description here

But now I want to change the width and number of columns with FP. I tried something like

\documentclass{book} 
\usepackage{array}
\usepackage{fp}
\begin{document}
\begin{tabular}{|*{4}{c|}}
\hline
a & b & c & d  \\
\hline
\multicolumn{3}{|c|}{a} & b \\
\hline
\FPmul\one{2}{2}
\FPdiv\two{1}{2}
\multicolumn{\one}{|>{\centering\arraybackslash}p{\two\textwidth}|}{a} & b & c\\
\hline
\end{tabular}
\end{document}

And I got the following error:

( FP-MUL ) ( FP-DIV )
! Misplaced \omit.
\multispan ->\omit 
                   \@multispan 
l.13 ...ng\arraybackslash}p{  \two\textwidth}|}{a}
                                                   & b & c\\

any help ? :/

  • Welcome to TeX.SE! – Cragfelt Dec 17 '17 at 23:29
  • \multicolumn should appear as the first item in the cell. The fp computations make TeX start a cell, so it's too late for \multicolumn. – egreg Dec 17 '17 at 23:32
  • And how can i do it? maybe without fp ? :/ – Nazime Lakehal Dec 17 '17 at 23:33
3

\multicolumn should appear as the first item in the cell. The fp computations make TeX start a cell, so it's too late for \multicolumn. You can use xfp instead:

\documentclass{book}
\usepackage{array}
\usepackage{xfp}
\begin{document}
\begin{tabular}{|*{4}{c|}}
\hline
a & b & c & d  \\
\hline
\multicolumn{3}{|c|}{a} & b \\
\hline
\multicolumn{2}{|>{\centering\arraybackslash}p{\fpeval{1/2}\textwidth}|}{a} & b & c\\
\hline
\end{tabular}
\end{document}

enter image description here

For the first argument to \multicolumn there is \inteval.

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.