2

Please, I need help. I'm trying to do this table, but I have some issues trying to merge the cells. I want to write something in those 3 rows merged but the text goes to another place and also there is not line to close those merged rows. Thanks in advanced.

  \documentclass{article}
\usepackage{multirow}
\begin{document}
\begin{tabular}{|c|c|c|c|c|}
\hline
%\cline{2-6}
      \multirow{2}{*}{Vehículo} & \multirow{2}{*}{Trayectos} & \multicolumn{3}{c {Movimientos} \\
    \cline{3-5}
    &                                                       & Id & Cantidad & Movimiento & 
\hline
    {\multirow{10}{*}{1}}
    & 5 - 20                                                & 1 & 1200 & 3100 & 
%\hline
    \cline{2-5}
    & 20 - 11                                               { \multirow{3}{*}{Sin movimiento}}
    \cline{2-5}

    & {\multirow{4}{*}{11 - 20}}                            & 40 & 1000 & 19100 \\
    \cline{3-5}
    &                                                       & 33 & 1000 & 3700 \\
    \cline{3-5}
    &                                                       & 17 & 1200 & 8800 \\
    \cline{3-5}
    &                                                       & 36 & 2000 & 24400 \\
    \cline{2-5}
    & 20 - 1                                                & & & &
    \cline{2-5}
    & {\multirow{2}{*}{1 - 20}}                             & 30 & 2000 & 9000 \\
    \cline{3-5}
    &                                                       & 1 & 3800 & 3100 \\
    \cline{2-5}
    & 20 - 5                                                & & & &
    \cline{1-5}
\end{tabular}
\end{document}
1
  • Welcome! Please make your code into a compilable example.
    – cfr
    Commented Jul 17, 2016 at 0:13

3 Answers 3

3

tabla

Try this:

    \documentclass{article}
    \usepackage[spanish]{babel}
    \usepackage[utf8]{inputenc}
    \usepackage{multirow, array}

\begin{document}
\renewcommand{\arraystretch}{1.5}
\begin{table}[h] \centering 
    \begin{tabular}{|c|c|c|c|c|}
        \hline
        \multirow{2}{*}{Vehículo} & \multirow{2}{*}{Trayectos} & \multicolumn{3}{c|}{Movimientos} \\ \cline{3-5}
                                  &                            & Id Producto & Cantidad & Precio  \\ \hline
           \multirow{10}{*}{1}    &           5 - 20           &      1      &   1200   &  3100   \\ \cline{2-5}
                                  &          20 - 11           &      \multicolumn{3}{c|}{}       \\ \cline{2-5}
                                  & {\multirow{4}{*}{11 - 20}} &     40      &   1000   &  19100  \\ \cline{3-5}
                                  &                            &     33      &   1000   &  3700   \\ \cline{3-5}
                                  &                            &     17      &   1200   &  8800   \\ \cline{3-5}
                                  &                            &     36      &   2000   &  24400  \\ \cline{2-5}
                                  &           20 - 1           &      \multicolumn{3}{c|}{}       \\ \cline{2-5}
                                  & {\multirow{2}{*}{1 - 20}}  &     30      &   2000   &  9000   \\ \cline{3-5}
                                  &                            &      1      &   3800   &  3100   \\ \cline{2-5}
                                  &           20 - 5           &      \multicolumn{3}{c|}{}       \\ \hline
    \end{tabular}
\end{table}
\end{document}
1
  • THANK YOU SO MUCH! IT WORKS PERFECTLY! Sorry, it was my first post and I didn't know how to fit all the code in the message.
    – user110209
    Commented Jul 17, 2016 at 0:36
1

A little late to be really useful for OP, but here is a solution using cals:

\documentclass{article}
\usepackage{cals}

\let\nc=\nullcell                                                  % Shortcuts
\let\sc=\spancontent
\newcommand{\ml}{\hspace*{1.75em}}

\begin{document}

\begin{table}[ht]

\begin{calstable}[c] % Centre the tabular

% Defining columns relative to the margin 
\colwidths{{\dimexpr(\columnwidth)/5\relax}
            {\dimexpr(\columnwidth)/5\relax}
            {\dimexpr(\columnwidth)/5\relax}
            {\dimexpr(\columnwidth)/5\relax}
            {\dimexpr(\columnwidth)/5\relax}
            }

% Set up the tabular
\makeatletter
\def\cals@framers@width{0.4pt}   % Outside frame rules, reduce if the rule is too heavy
\def\cals@framecs@width{0.4pt}
\def\cals@bodyrs@width{0.4pt}
\def\cals@cs@width{0.4pt}             % Inside rules, reduce if the rule is too heavy
\def\cals@rs@width{0.4pt}

% R1H1
\thead{\bfseries
\brow
    \nc{lrt}
    \nc{lrt}
    \nc{ltb}
    \nc{tb}
    \nc{rtb}\alignC\sc{\vfil Movimientos}
\erow
% R2H2
\brow
    \nc{lrb}\alignC\sc{\vfil Vehículo}
    \nc{lrb}\alignC\sc{\vfil Trayectos}
    \alignC\cell{\vfil Id Producto}
    \alignC\cell{\vfil Cantidad}
    \alignC\cell{\vfil Precio }
\erow
\mdseries
}
% R3B1
\brow
    \nc{lrt}
    \alignC\cell{\vfil 5 -- 20}
    \alignR\cell{\vfil 1\ml}
    \alignC\cell{\vfil 1200}
    \alignR\cell{\vfil 3100\ml}
\erow
% R4B2
\brow
    \nc{lr}
    \alignC\cell{\vfil 20 -- 11}
    \nc{ltb}
    \nc{tb}
    \nc{rtb}\sc{}
\erow
% R5B3
\brow
    \nc{lr}
    \nc{lrt}
    \alignR\cell{\vfil 40\ml}
    \alignC\cell{\vfil 1000}
    \alignR\cell{\vfil 19\,100\ml}
\erow
% R6B4
\brow
    \nc{lr}
    \nc{lr}
    \alignR\cell{\vfil 33\ml}
    \alignC\cell{\vfil 1000}
    \alignR\cell{\vfil 3700\ml}
\erow
% R7B5
\brow
    \nc{lr}
    \nc{lr}
    \alignR\cell{\vfil 17\ml}
    \alignC\cell{\vfil 1200}
    \alignR\cell{\vfil 8800\ml}
\erow
% R8B6
\brow
    \nc{lr}
    \nc{lrb}\alignC\sc{\vfil 11 -- 20}
    \alignR\cell{\vfil 36\ml}
    \alignC\cell{\vfil 2000}
    \alignR\cell{\vfil 24\,400\ml}
\erow
% R9B7
\brow
    \nc{lr}
    \alignC\cell{\vfil 20 -- 1}
    \nc{ltb}
    \nc{tb}
    \nc{rtb}\sc{}
\erow
% R10B8
\brow
    \nc{lr}
    \nc{lrt}
    \alignR\cell{\vfil 30\ml}
    \alignC\cell{\vfil 2000}
    \alignR\cell{\vfil 9000\ml}
\erow
% R11B9
\brow
    \nc{lr}
    \nc{lrb}\alignC\sc{\vfil 1 -- 20}
    \alignR\cell{\vfil 1\ml}
    \alignC\cell{\vfil 3800}
    \alignR\cell{\vfil 3100\ml}
\erow
% R12B10
\brow
    \nc{lrb}\alignC\sc{\vfil 1}
    \alignC\cell{\vfil 20 -- 5}
    \nc{ltb}
    \nc{tb}
    \nc{rtb}\sc{}
\erow
\makeatletter
\end{calstable}\par % \par to align the tabular
\end{table}

\end{document}

enter image description here

0

You can do that table easily with {NiceTabular} of nicematrix.

In {NiceTabular}, you merge cells both horizontally and vertically with the command \Block. For the rows, you give the number of logical rows (and not the number of physical lines as with \multicolumn).

With the key hvlines, all the rules are drawn, excepted in the blocks (constructed by \Block).

\documentclass{article}
\usepackage[spanish]{babel}
\usepackage{nicematrix}

\begin{document}
\renewcommand{\arraystretch}{1.5}
\begin{table}[h] \centering 
\begin{NiceTabular}{ccccc}[hvlines]
\Block{2-1}{Vehículo} & \Block{2-1}{Trayectos} & \Block{1-3}{Movimientos}         \\ 
                      &                        & Id Producto & Cantidad & Precio  \\ 
\Block{*-1}{1}        &           5 - 20       &      1      &   1200   &  3100   \\ 
                      &          20 - 11       & \Block{1-3}{} \\
                      & \Block{4-1}{11 - 20}   &     40      &   1000   &  19100  \\ 
                      &                        &     33      &   1000   &  3700   \\ 
                      &                        &     17      &   1200   &  8800   \\ 
                      &                        &     36      &   2000   &  24400  \\ 
                      &           20 - 1       & \Block{1-3}{} \\
                      & \Block{2-1}{1 - 20}    &     30      &   2000   &  9000   \\ 
                      &                        &      1      &   3800   &  3100   \\ 
                      &           20 - 5       & \Block{1-3}{} \\
\end{NiceTabular}
\end{table}
\end{document}

Output of the above code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .