0

I'm trying to create a table with the following structure:

enter image description here

Using the following code:

    \begin{table}[htp]
    \centering
    \begin{tabular}{ |l|l|l|l| }
        \hline
        \rowcolor{gray!50}
        \textbf{Posición} & \textbf{Función del Campo} & \textbf{Código Descripción} &\textbf{Valores} \\
        \hline
        1 & Indicador de Centro & Indica que se trata de un centro & C\\
        \hline
        2 & Tipo de Centro & \multirow{2}{*}{Indica que tipo de centro se trata} & Z para Centros Zonales & I para Centros Intermedios\\
        \hline
        3 - 5 & Localización & Localización del Centro & Tres primeras de ubicación pej: Valencia: VAL\\
        \hline
        6 & Numero de Centro & Ordenación de los punto de presencia & Ascendente dependiendo de fecha de instalación\\
        \hline
    \end{tabular}
    \caption{Nomenclatura Centros Zonales e Intermedios}
    \label{table:Centros}
 \end{table}

The result is as follows:

enter image description here

How do I fix it so that not only does the multirow works how in the correct place but also the cable doesn't overflow from the page.

Thank you in advance,

PS. Open to suggestions about colours

2
  • 1
    your example (please always make full document) produces ! Extra alignment tab has been changed to \cr. so the pdf output that you show is arbitrary, you should look at the log not the pdf after an error. I couldn't work out the intended location of I para Centros Intermedios ? Feb 1, 2016 at 12:33
  • Just updated the first image to make it more clear. Thank you for your help
    – Neptune
    Feb 2, 2016 at 8:33

1 Answer 1

1

This still needs some work to be done, but you may start with:

% arara: pdflatex

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[spanish]{babel}
\usepackage[table]{xcolor}
\usepackage{array}
\usepackage{microtype}
\usepackage{siunitx}
\sisetup{range-phrase=--}
\usepackage{ragged2e}

\begin{document}
\begin{table}[htp]
    \centering
    \begin{tabular}{|*{4}{>{\RaggedRight\let\newline\\\arraybackslash\hspace{0pt}}p{\dimexpr( \textwidth-5\arrayrulewidth-8\tabcolsep)/4}|}}
        \hline
        \rowcolor{gray!50}
        \textbf{Posición} & \textbf{Función del Campo} & \textbf{Código Descripción} &\textbf{Valores} \\
        \hline
        $1$ & Indicador de Centro & Indica que se trata de un centro & C\\
        \hline
        $2$ & Tipo de Centro & Indica que tipo de centro se trata & Z para Centros Zonales  I para Centros Intermedios\\
        \hline
        \numrange{3}{5} & Localización & Localización del Centro & Tres primeras de ubicación pej: Valencia: VAL\\
        \hline
        6 & Numero de Centro & Ordenación de los punto de presencia & Ascendente dependiendo de fecha de instalación\\
        \hline
    \end{tabular}
    \caption{Nomenclatura Centros Zonales e Intermedios}\label{table:Centros}
\end{table} 
\end{document}

I was not too sure about where to put everything (see Mr. Carlisle's comment). The thickness of the vertical lines still needs to be subtracted (done already in edit, trick taken from David) here. I would omit those lines completely.

The first columns could be made narrower of course. Just edit the column definitions as you please. All those topics are treated a lot on this homepage here.

enter image description here

5
  • 1
    I guess you were first, I'll delete mine:-) Feb 1, 2016 at 12:40
  • @DavidCarlisle As thanks for that noble gesture I have stolen your much cooler \dimexpr(...) :-)
    – LaRiFaRi
    Feb 1, 2016 at 12:44
  • Just updated the first image to show how I would like the table to look in my document.
    – Neptune
    Feb 2, 2016 at 8:32
  • @Neptune the last column is in vertical mode so you could use (for example) blank line \hrule blank line between the two paragraphs starting Z para and I para... Feb 2, 2016 at 9:03
  • @DavidCarlisle unfortunately that doesn't work :(
    – Neptune
    Feb 3, 2016 at 11:12

You must log in to answer this question.

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