1

If I run the following code I got a table with a multicolumn of 5 but if I place an \hline before the multicolumn as seen in the code it closes all the table in the upper part. How can I close only the 5 multicolumn leaving the other part without lines?

\begin{tabular}{|r{1.5cm}|c{1.5cm}|c{1.5cm}|c{1.5cm}|c{1.5cm}|c{2.5cm}|c{1.33cm}|c{1.3cm}|c{2cm}|}
\hline %with this command the line is for all the table not just the 5 columns
\multicolumn{5}{|c|}{Mensual} \\
\hline
& L\'iquido & S. Social & IRPF & TOTAL & Anual l\'iquido & \multicolumn{2}{|c|}{} & Total Anual\\ 
Nombre & (A) & (B) & (C) & A+B+C & (D) = A $\times$ pagas& \multicolumn{2}{|c|}{Por Caja o ``B''} & (D) + Caja\\ \hline
Jos\'e & 2.563,56 \euro & 172,82 \euro & 864,12 \euro & 3.600,5 \euro & \textbf{38.453 \euro} & 21.295 \euro & 9.851 \euro & \textbf{69.599 \euro}\\ \hline
Pedro & 1.949,50 \euro & 170,60 \euro & 669,50 \euro & 2.789,6 \euro & \textbf{41.844 \euro} & \multicolumn{2}{|c|}{Sin Datos}& \textbf{41.844 \euro}\\ \hline
Antonio & 2.240,72 \euro & 181,99 \euro & 601,84 \euro & 3.024,6 \euro & \textbf{26.889 \euro} & \multicolumn{2}{|c|}{10.125 \euro}& \textbf{37.014 \euro}\\ \hline
Lina & 1.870,12 \euro & 152,01 \euro & 334,13 \euro & 2.356,3 \euro & \textbf{28.052 \euro} & \multicolumn{2}{|c|}{Sin Datos}& \textbf{28.052 \euro}\\ \hline
\end{tabular}
  • your title and tag mentions multirow (for the multirow package) but the code shown foes not use \multirow but \multicolumn (and is not a complete example that anyone can run. Please make the question clearer. – David Carlisle Jun 19 '16 at 11:26
  • 2
    r{1.5cm} and c{1.5cm} are syntax errors unless you are using some very non standard package. – David Carlisle Jun 19 '16 at 11:27
  • 1
    E.g. \cline{1-5} after removing errors in your code. – Kola B. Jun 19 '16 at 11:27
  • Yes, you are right. Next time I'll try to be more accurate. Thanks for the advice. – José Jun 19 '16 at 17:38
2

an alternative with use of siunitx and similar "open look" of table as propsed Mico in his answer:

\documentclass{article}
\usepackage{booktabs, makecell}
\usepackage{eurosym}
\usepackage{siunitx}

\usepackage{etoolbox}
\newcommand{\B}{\fontseries{b}\selectfont} % renew def. for non-extended bold font
\robustify\B


\begin{document}

\begingroup
    \sisetup{detect-weight,
            output-decimal-marker={,},
            group-minimum-digits=4,
            group-separator={.}
            }
    \setlength\tabcolsep{3pt}
    \small
\begin{tabular}{@{}l
                S[table-format=4.2]
           *{2}{S[table-format=3.2]}
                S[table-format=4.1]
                S[table-format=4.0]
                S[table-format=5.0]
                S[table-format=4.0]
                S[table-format=5.0]
                @{}}
    \toprule
    & \multicolumn{4}{c}{Mensual}   &   \multicolumn{4}{c}{}    \\
    \cmidrule(lr){2-5}
\thead[b]{Nombre}
    &   {\thead[b]{L\'iquido\\ (A)}}
        &   {\thead[b]{S. Social\\ (B)}}
            &   {\thead[b]{IRPF\\ (C)}}
                &   {\thead[b]{TOTAL\\ (A + B + C)}}
                    &   {\thead[b]{Anual l\'iquido (D)\\
                        $=(\mathrm{A})\times \mathrm{paagas}$}}
                        &   \multicolumn{2}{c}{\thead[b]{Por Caja o ``B''}}
                            &   {\thead[b]{Total Anual\\
                                $(D) + \mathrm{Caja}$}}                              \\
    \cmidrule(lr){7-8}
    & {\euro} & {\euro} & {\euro} & {\euro} & {\euro} & {\euro} & {\euro} & {\euro} \\
     \midrule
Jos\'e  & 2 563.56  & 172.82 & 864.12  & 3 600.5 & \B 38 453 & 21 295 & 9 851  & \B 69 599 \\ Pedro   & 1 949.50  & 170.60 & 669.50  & 2 789.6 & \B 41 844
            &   \multicolumn{2}{c}{Sin Datos}    & \B 41 844         \\
Antonio & 2 240.72  & 181.99 & 601.84  & 3 024.6 & \B 26 889
            &   \multicolumn{2}{c}{10.125}       & \B 37 014        \\
Lina    & 1 870.12  & 152.01 & 334.13 & 2 356.3  & \B 28 052
            &   \multicolumn{2}{c}{Sin Datos}    & \B 28 052        \\
\bottomrule
    \end{tabular}
    \end{document}

enter image description here

| improve this answer | |
3

As far as I can tell, there's no need to specify exact widths for any of the columns, especially as automatic line wrapping would seem to be inappropriate. Just use the "standard" column types -- l, c, and r -- instead.

Your table does have quite few columns, and it thus won't fit on a normal-sized page in portrait mode (unless you select a minuscule font size). I therefore suggest you typeset the table in landscape mode instead -- using, say, the sidewaystable environment provided by the rotating package.

enter image description here

\documentclass[spanish]{article}
\usepackage[T1]{fontenc}
\usepackage[spanish]{babel}  % or 'portuguese' ?
\usepackage{array,eurosym,rotating}
\begin{document}

\begin{sidewaystable}
\setlength\extrarowheight{2pt}  
\centering
\begin{tabular}{|l|*{8}{c|}}
\cline{1-5}
\multicolumn{5}{|c|}{Mensual} \\
\hline
Nombre & L\'iquido & S. Social & IRPF & Total & Anual l\'iquido & \multicolumn{2}{c|}{Por Caja o ``B''} & Total Anual\\ 
& (A) & (B) & (C) & (A)+(B)+(C) & (D) = A$\times$pagas& \multicolumn{2}{c|}{} & (D) + Caja\\ 
\hline
Jos\'e & 2.563,56 \euro & 172,82 \euro & 864,12 \euro & 3.600,5 \euro & \textbf{38.453 \euro} & 21.295 \euro & 9.851 \euro & \textbf{69.599 \euro}\\ 
\hline
Pedro & 1.949,50 \euro & 170,60 \euro & 669,50 \euro & 2.789,6 \euro & \textbf{41.844 \euro} & \multicolumn{2}{c|}{Sin Datos}& \textbf{41.844 \euro}\\ 
\hline
Antonio & 2.240,72 \euro & 181,99 \euro & 601,84 \euro & 3.024,6 \euro & \textbf{26.889 \euro} & \multicolumn{2}{c|}{10.125 \euro}& \textbf{37.014 \euro}\\ 
\hline
Lina & 1.870,12 \euro & 152,01 \euro & 334,13 \euro & 2.356,3 \euro & \textbf{28.052 \euro} & \multicolumn{2}{c|}{Sin Datos}& \textbf{28.052 \euro}\\ 
\hline
\end{tabular}
\end{sidewaystable}

\end{document}

Addendum: You should also give some thought to giving your table a more "open" look, in order to make it look more inviting and welcoming to your readers. To achieve such a look, do consider (i) getting rid of all vertical lines and most horizontal lines and (ii) using the macros of the booktabs package for the remaining horizontal lines. To further enhance readability, consider putting the euro symbols in a separate header row.

enter image description here

\documentclass[spanish]{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[spanish]{babel}  % or 'portuguese' ?
\usepackage{eurosym,rotating,booktabs}
\begin{document}

\begin{sidewaystable} 
\centering
\begin{tabular}{@{}l*{8}{c}@{}}

\multicolumn{5}{@{}c}{Mensual} \\
\cmidrule(r){1-5}
Nombre & L\'iquido & S. Social & IRPF & Total & Anual l\'iquido & \multicolumn{2}{c}{Por Caja o ``B''} & Total Anual\\ 
& (A) & (B) & (C) & (A)+(B)+(C) & (D) = (A)$\times$pagas& & & (D) + Caja\\ 
\cmidrule(lr){7-8}
& (\euro) & (\euro) & (\euro) & (\euro) & (\euro) & (\euro) & (\euro) & (\euro) \\
\midrule
Jos\'e & 2.563,56 & 172,82 & 864,12 & 3.600,50 & \textbf{38.453} & 21.295 & 9.851 & \textbf{69.599}\\ 
\addlinespace
Pedro & 1.949,50 & 170,60 & 669,50 & 2.789,60 & \textbf{41.844} & \multicolumn{2}{c}{Sin Datos}& \textbf{41.844}\\ 
\addlinespace
Antonio & 2.240,72 & 181,99 & 601,84 & 3.024,55 & \textbf{26.889} & \multicolumn{2}{c}{10.125\,\euro}& \textbf{37.014}\\ 
\addlinespace
Lina & 1.870,12 & 152,01 & 334,13 & 2.356,26 & \textbf{28.052} & \multicolumn{2}{c}{Sin Datos}& \textbf{28.052}\\ 
\bottomrule
\end{tabular}
\end{sidewaystable}

\end{document}
| improve this answer | |
  • Great!! Excellent solutions both. I will give to the table more "open" look. Thanks and regards. – José Jun 19 '16 at 17:39
  • And by the way. Spanish!! Always spanish!! Nothing to do with Portugal ;) – José Jun 19 '16 at 17:41
  • @José - So I guessed right, at least on the language option... – Mico Jun 19 '16 at 17:44
0
\documentclass{article}
\usepackage{multirow}
\usepackage{eurosym}
\begin{document}
\begin{tabular}{|p{1.5cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.5cm}|p{0.9cm}|p{0.6cm}|p{1.2cm}|}
    \hline %with this command the line is for all the table not just the 5 columns 
\multicolumn{5}{|c|}{Mensual} &\multicolumn{4}{c|}{}\\ %needed to insert line break 
    \hline
    & L\'iquido & S. Social & IRPF & TOTAL & Anual l\'iquido & \multicolumn{2}{|c|}{} & Total Anual\\ 
    Nombre & (A) & (B) & (C) & A+B+C & (D) = A $\times$ pagas& \multicolumn{2}{|c|}{Por Caja o ``B''} & (D) + Caja\\ \hline
    & \euro & \euro & \euro & \euro &\euro & \euro & \euro & \euro \\\hline
    Jos\'e & 2.563,56 & 172,82 & 864,12  & 3.600,5 & \textbf{38.453} & 21.295 & 9.851  & \textbf{69.599 }\\ \hline
    Pedro & 1.949,50 & 170,60  & 669,50  & 2.789,6 & \textbf{41.844 } & \multicolumn{2}{|c|}{Sin Datos}& \textbf{41.844 }\\ \hline
    Antonio & 2.240,72  & 181,99 & 601,84  & 3.024,6  & \textbf{26.889 } & \multicolumn{2}{|c|}{10.125}& \textbf{37.014}\\ \hline
    Lina & 1.870,12  & 152,01 & 334,13 & 2.356,3  & \textbf{28.052} & \multicolumn{2}{|c|}{Sin Datos}& \textbf{28.052 }\\ \hline
    \end{tabular}
    \end{document}

eurotbl

| improve this answer | |
  • Unless the text block happens to be quite wide -- a subject about which the OP, unfortunately, provided no information -- this table won't fit on either an a4-sized or a letter-sized page in portrait mode. – Mico Jun 19 '16 at 14:13

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.