1

I'm starting with LaTeX and I have doubts about editing this table here. First, I'd like to know how to complete the vertical lines, and also I want to know a way to indent text in the "Concepto" column. Thank you all. enter image description here

\documentclass[12pt,twoside]{report}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\begin{table}[h]
\centering 
\begin{tabular}{| l | c c c c c |} 
\toprule 
& \multicolumn{5}{c |}{Presupuesto} \\ 
\cmidrule(l){2-6} 

Concepto &  &  &  &  & Precio (\euro)\\ 

\midrule 
\midrule 

Matrícula de inscripción &  &  &  &  & 1.800\\ %  row 1
Viaje en avión &  &  &  &  & 500\\ % row 2
PPD234 &  &  &  &  & 0.965\\ %  row 3
JSB126 &  &  &  &  & \\ %  row 4
JSB724 &  &  &  &  & 0.937\\ %  row 5

\midrule 
\midrule 
Total &  &  &  &  & \\ 
\bottomrule 
\end{tabular}
\label{tab:template} 
\end{table}
  • 2
    Welcome to TeX.SE! Can you please complete your code snippet to be compilable? – Mensch Jan 16 '17 at 18:04
  • 4
    Rules from package booktabs (toprule, bottomrule, etc.) are incompatible with vertical lines. It is a design concept. You can read more about it in the booktabs manual. – Johannes_B Jan 16 '17 at 18:08
3
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{siunitx}
\usepackage{array, booktabs}

\begin{document}
\begin{table}[h]
\centering
\begin{tabular}{| l | c c c c c |}
    \hline
    &   \multicolumn{5}{c|}{Presupuesto}   \\
    \cline{2-6}
    Concepto &  &  &  &  & Precio (euro)\\
    \hline
    \hline
    Matrícula de inscripción &  &  &  &  & 1.800\\ %  row 1
    Viaje en avión &  &  &  &  & 500\\ % row 2
    PPD234 &  &  &  &  & 0.965\\ %  row 3
    JSB126 &  &  &  &  & \\ %  row 4
    JSB724 &  &  &  &  & 0.937\\ %  row 5
    \hline
    \hline
    Total &  &  &  &  & \\
    \hline
\end{tabular}
    \label{tab:template}
\end{table}

or

    \begin{table}[h]
    \centering
\begin{tabular*}{\linewidth}{l @{\extracolsep{\fill}} S[table-format=3.3]}
    \toprule
                            &  {Presupuesto}        \\
    \cmidrule{2-2}
Concepto                    &   {Precio (euro)}     \\
    \midrule 
Matrícula de inscripción    &     1.800             \\ %  row 1
Viaje en avión              &   500                 \\ % row 2
PPD234                      &     0.965             \\ %  row 3
JSB126                      &                       \\ %  row 4
JSB724                      &     0.937             \\ %  row 5
    \midrule
Total                       &                       \\
    \bottomrule
\end{tabular*}
    \label{tab:template}
\end{table}

\newpage
or the first example added in addendum

    \begin{table}[h]
    \centering
\begin{tabular*}{0.6\linewidth}{>{\quad}l @{\extracolsep{\fill}} S[table-format=3.3]}
    \toprule
                            &  {Presupuesto}        \\
    \cmidrule{2-2}
\multicolumn{1}{l}{Concepto}                    
                            &   {Precio (euro)}     \\
    \midrule
Matrícula de inscripción    &     1.800             \\ %  row 1
Viaje en avión              &   500                 \\ % row 2
PPD234                      &     0.965             \\ %  row 3
JSB126                      &                       \\ %  row 4
JSB724                      &     0.937             \\ %  row 5
    \midrule
Total                       &                       \\
    \bottomrule
\end{tabular*}
    \label{tab:template}
\end{table}

or the second example with indented only one cell content

    \begin{table}[h]
    \centering
\begin{tabular*}{0.6\linewidth}{l @{\extracolsep{\fill}}
                                        S[table-format=4.0]<{\texteuro}}
    \toprule
                            &  \mcc{Presupuesto}    \\
    \cmidrule{2-2}
Concepto                    &   \mcc{Precio}        \\
    \midrule
Matrícula de inscripción    &  1800.00              \\ %  row 1
\quad Viaje en avión        &   500.00              \\ % row 2
PPD234                      &     0.96              \\ %  row 3
JSB126                      &   \mcc{}              \\ %  row 4
JSB724                      &     0.93              \\ %  row 5
    \midrule
Total                       &   \mcc{}              \\
    \bottomrule
\end{tabular*}
    \label{tab:template}
\end{table}


and last example also added in as addendum

    \begin{table}[h]
    \centering
\begin{tabular*}{0.6\linewidth}{l @{\extracolsep{\fill}} S[table-format=3.3]}
    \toprule
                            &  {Presupuesto}        \\
    \cmidrule{2-2}
\multicolumn{1}{c}{Concepto}
                            &   {Precio (euro)}     \\
    \midrule
Matrícula de inscripción    &     1.800             \\ %  row 1
Viaje en avión              &   500                 \\ % row 2
PPD234                      &     0.965             \\ %  row 3
JSB126                      &                       \\ %  row 4
JSB724                      &     0.937             \\ %  row 5
    \midrule
Total                       &                       \\
    \bottomrule
\end{tabular*}
    \label{tab:template}
\end{table}


\end{document}

Edit: You should provide complete small document starting with \begin{document} following wit only necessary packages and ending with `\end{document}.

In second example I assume, that your table actually has onla two columns and that you like to have table width equal to \textwidth. If this is not a case, you can reduce table width for example to 0.5\linewidth.

Beside showed two examples exist many other possibilities. One of them you find in nice Jan's answer.

enter image description here

Addendum: according to your comments three more examples are added to above MWE:

enter image description here

  • 1
    I think OP means one thousand eight hundred by 1.800 @Doma17 – Kurzd Jan 16 '17 at 18:46
  • 2
    maybe, but what then means by 0.965? anyway, this is simple to correct, if OP will edit his question and provide complete MWE and clearly indicate what number suppose to be (without any separators for thousandth) :) – Zarko Jan 16 '17 at 18:54
  • The numbers are just to fill while I get the right ones to put in. Thank you so much for the solutions, also, the second thing that I said I'd like to do is not changing the width of table, what I want to do is the text "Viaje en avión" to be indented (with a Tab button press) below "Matrícula de inscripción". – Doma17 Jan 17 '17 at 15:35
  • Also, those are prices in euros, and will have the format "1.800,23", How can I adjust the second table (suits me better) so it displays the prices in a neat way? – Doma17 Jan 17 '17 at 16:38
  • It's getting close, but how can I indent just one line? edit: Also how can I make that "500" centered? – Doma17 Jan 17 '17 at 17:00
3

I'd suggest, that you use package dcolumn to present the last column, in order to align it at the decimal point of your numbers. Also I suggest, that you leave the vertical lines aside.

In my example, I also changed the table layout to be only three columns, that is, the bunch of empty c columns was joined in one (still empty) column.

I defined new column types, to make the typing easier. I also added @{}, to get rid of the unused white space on the left and right of the table.

Code

\documentclass{article}
\usepackage[utf8]{luainputenc}
\usepackage[T1]{fontenc}
\usepackage{array}
\usepackage{dcolumn}
\usepackage{booktabs}
\usepackage[gen,right]{eurosym}


%% Define new columntypes.  First a column for the header of the
%% table.  (Identifier H for header)
\newcolumntype{H}{>{\footnotesize}c}
%% Second, a decimal column 
\newcolumntype{d}[1]{D{.}{.}{#1}}

\begin{document}

\begin{tabular}{@{} lld{3} @{}}
  \toprule
  \multicolumn{1}{@{} H}{Concepto}
  & \multicolumn{2}{H @{}}{Presuquesto}\\
  && \multicolumn{1}{H @{}}{Precio (\EUR{})}\\
  \midrule
  Matrícula de inscripción & & 1.800 \\
  Viaje en avión && 500 \\
  PPD234 && 0.965 \\
  JSB126\\
  JSB724 && 0.937\\
  \addlinespace
  Total \\
  \bottomrule
\end{tabular}
\end{document}

Result

enter image description here

EDIT: Zarko was faster and presented nearly the same solution. :-)

  • I know aligning the decimal point is the 'typical' thing to do, but if there numbers were to stay like this, i would highly recommend not using this approach. In my opinion, aligning decimal points is overused and not always pretty. If your numbers span roughly the same number of characters, it's fine, but i've seen plenty of examples where this was not the case. – pschulz Jan 17 '17 at 17:48
3

Booktabs adds some padding around its rules (\aboverulesep and \belowrulesep), whence the‘incomplete’ vertical rules or coloured cells. You can set the values of these lengths to 0pt, in order to keep the variable width feature. However, in the opinion of many, tables in general look more professional without vertical rules:

\documentclass{article}
\usepackage[utf8]{inputenc} %
\usepackage[T1]{fontenc} %
\usepackage{textcomp} 
\let\euro\texteuro
\usepackage{array, hhline, booktabs}

\begin{document}

       \begin{table}[h]
        \centering\setlength\aboverulesep{0pt}\setlength\belowrulesep{0pt}
        \begin{tabular}{| l | c c c c c |}
            \toprule
            & \multicolumn{5}{c |}{Presupuesto} \\
            \cmidrule{2-6}

            Concepto & & & & & Precio (\euro)\\

            \midrule
            \midrule

            Matrícula de inscripción & & & & & 1.800\\ % row 1
            Viaje en avión & & & & & 500\\ % row 2
            PPD234 & & & & & 0.965\\ % row 3
            JSB126 & & & & & \\ % row 4
            JSB724 & & & & & 0.937\\ % row 5

            \midrule
            \midrule
            Total & & & & & \\
            \bottomrule
        \end{tabular}
        \label{tab:template}
    \end{table}

       \begin{table}[h]
        \centering\setlength{\extrarowheight}{1pt}
        \begin{tabular}{lc c c c c}
            \toprule
            & \multicolumn{5}{c}{Presupuesto} \\
            \cmidrule(lr){2-6}

            Concepto & & & & & Precio (\euro)\\

            \midrule
            \midrule

            Matrícula de inscripción & & & & & 1.800\\ % row 1
            Viaje en avión & & & & & 500\\ % row 2
            PPD234 & & & & & 0.965\\ % row 3
            JSB126 & & & & & \\ % row 4
            JSB724 & & & & & 0.937\\ % row 5

            \midrule
            \midrule
            Total & & & & & \\
            \bottomrule
        \end{tabular}
        \label{tab:template}
    \end{table}
\end{document} 

enter image description here

Note other packages allow variable thickness horizontal lines: makecell has \Xhline and Xcline, with the thickness as a mandatory argument. Boldline has the \hlineB and \clineB commands, with the number of times basic line thickness as a mandatory argument. You also have V{some number} as a substitute for | in tables preambles.

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.