4

I am writing a thesis in a large .tex file in Vim. As I show in this image, the first, second and third column have different spacing (width):

enter image description here

This is the code for the table:

\begin{table}[h]
\centering
\begin{tabular}{|c|c|c|c|}
\hline 
\multicolumn{3}{|c|}{\begin{tabular}[c]{@{}c@{}}Números cuánticos \\[-0.1cm] del estado excitado\end{tabular}} & \multirow{2}{*}{\begin{tabular}[c]{@{}c@{}}\\[-0.95cm]Frecuencias \\[-0.2cm] de absorción \\[-0.2cm] experimentales \\[-0.2cm] (cm\textsuperscript{-1})\end{tabular}} \\ \cline{1-3}
$v _{1}$ & $v _{2}$ & $v _{3}$ &  \\ \hline
$0$ & $1$ & $0$ & $1594{.}59$ \\ \hline
$1$ & $0$ & $0$ & $3656{.}65$ \\ \hline
$0$ & $0$ & $1$ & $3755{.}79$ \\ \hline
$0$ & $2$ & $0$ & $3151{.}40$ \\ \hline
$0$ & $1$ & $1$ & $5332{.}00$ \\ \hline
$0$ & $2$ & $1$ & $6874{.}00$ \\ \hline
$1$ & $0$ & $1$ & $7251{.}60$ \\ \hline
$1$ & $1$ & $1$ & $8807{.}05$ \\ \hline
$2$ & $0$ & $1$ & $10613{.}12$ \\ \hline
$0$ & $0$ & $3$ & $11032{.}36$ \\ \hline
\end{tabular}
\end{table}

I would like to make first, second and third column the same width.

The rest of the tables in the .tex file are fine, except for this particular table. This way, I would not prefer to write commands in the preamble, due to this will modify all tables.

I would only like to equal the space of first, second and third columns only in this particular table.

My preamble is this:

\documentclass[12pt,a4paper,twoside,openany]{report}
\usepackage[left=2.5cm,top=2.5cm,right=2.5cm,bottom=2.5cm]{geometry}
\parindent 1 true cm
\usepackage[dvips]{graphicx}
\usepackage{eufrak}
\usepackage[spanish]{babel}
\usepackage[latin1]{inputenc}  
\usepackage[T1]{fontenc}
\usepackage{times}
\usepackage{amsmath}
\usepackage{graphicx,epsfig}
\usepackage{multirow}
\usepackage{float}
\usepackage{color}
\usepackage[longnamesfirst,super]{natbib} 
\setcitestyle{square} 
\usepackage{fancyhdr}    
\pagestyle{fancy}                                     
\renewcommand{\chaptermark}[1]{\markboth{\thechapter .\ #1}{}}         
\renewcommand{\sectionmark}[1]{\markright{\thesection .\ #1}{}} 
\lhead{\nouppercase}
\rhead{\nouppercase}
\fancyhead[LE]{{\sf \leftmark}}                                 
\fancyhead[RE]{}                                                
\fancyhead[RO]{{\sf \rightmark}}                              
\fancyhead[LO]{} 
\fancyfoot[LE,RO]{\thepage}
\fancyfoot[CE,CO]{}                                                         
\renewcommand{\headrulewidth}{0.0pt}                                
\renewcommand{\baselinestretch}{1.25}
\usepackage{adjustbox}
\usepackage{enumerate}
\usepackage{courier}
\begin{document}

I would appreciate very much if someone could help me, making tests with my preamble, and the code that introduces the table. (I am writing the thesis .tex file in Vim).

1
2

Specifying a fixed-width set of columns (for the first 3) helps solve this problem:

enter image description here

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{array,booktabs}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\begin{document}

\begin{tabular}{*{3}{C{2em}}c}
\toprule
\multicolumn{3}{c}{\begin{tabular}[t]{@{}c@{}}Números cuánticos \\[-0.1cm] del estado excitado\end{tabular}} 
&  \smash{\begin{tabular}[t]{@{}c@{}}Frecuencias \\[-.3em] de absorción \\[-.3em] experimentales \\[-.3em] (cm\textsuperscript{-1})\end{tabular}} \\ \cmidrule{1-3}
$v _{1}$ & $v _{2}$ & $v _{3}$ &  \\ \midrule
0 & 1 & 0 & 1594.59 \\ 
1 & 0 & 0 & 3656.65 \\ 
0 & 0 & 1 & 3755.79 \\ 
0 & 2 & 0 & 3151.40 \\ 
0 & 1 & 1 & 5332.00 \\ 
0 & 2 & 1 & 6874.00 \\ 
1 & 0 & 1 & 7251.60 \\ 
1 & 1 & 1 & 8807.05 \\ 
2 & 0 & 1 & \llap{1}0613.12 \\ 
0 & 0 & 3 & \llap{1}1032.36 \\ 
\bottomrule
\end{tabular}
\end{document}

I've done so using a 2em column of type C (centered, with the aid of array).

7
  • The result of cm\textsuperscript{-1} looks less than great. You may want to try cm${}^{-1} to get a proper minus sign.
    – Mico
    May 27 '14 at 21:39
  • @Werner I appreciate very much the answer. These weeks I have really been trying very hard this solution, but the use of these packages changes the aspect of the rest of the columns of the document, and it turns out to be a complete mess!! Would it be a simplest way to fix (with a command, such as {p}) the first two columns so that the their width results similar to the third column ?
    – DavidC.
    Jun 16 '14 at 17:35
  • 1
    @DavidC.: Yes. I've used C{<len>}, which results in p{<len>} with an added \centering using the array package. If you only use p{<len>}, then you will have flush-left content in those columns, or you have to manually add \centering (and \arraybackslash). You could also use the collcell package to set contents centred. However, why would the use of packages "change the aspect of the rest of the columns in your document though"?
    – Werner
    Jun 16 '14 at 17:42
  • @Werner Thank you for the response. What I meant to say is that there are a lot of "very big tables" in the document, (with adjustbox commands and so on) and they are modified while following the first answers. I beleive this last answer from today will work, but I don't really know how to implement your answer, could you give me the code for the table and a MWE please ? Thank you very much.
    – DavidC.
    Jun 16 '14 at 18:25
  • 1
    @DavidC.: So you want the widths of columns 1 & 2 to be the same, but different from that of columns 3 & 4? Currently columns 1-3 all have the same width (2em), while column 4 has a natural width as decided by my line breaks.
    – Werner
    Jul 1 '14 at 2:29
5

I switched to S columns from the sinunitx package; I also present an option without vertical rules and using the booktabs package (I suppresses packages and commands not relevant to the problem):

\documentclass[12pt,a4paper,twoside,openany]{report}
\usepackage[latin1]{inputenc}
\usepackage{multirow}
\usepackage{siunitx}
\usepackage{booktabs}

\renewcommand{\baselinestretch}{1.25}

\begin{document}

\begin{table}
\centering
\begin{tabular}{|S[table-format = 3.2]|S[table-format = 3.2]|S[table-format = 3.2]|S[table-format = 5.2]|}
\hline 
\multicolumn{3}{|c|}{\begin{tabular}[c]{@{}c@{}}Números cuánticos \\[-0.1cm] del estado excitado\end{tabular}} 
&  \multirow{2}{*}{\begin{tabular}[c]{@{}c@{}}\\[-0.95cm]Frecuencias \\[-0.2cm] de absorción \\[-0.2cm] experimentales \\[-0.2cm] (\si{\per\cm})\end{tabular}} \\ \cline{1-3}
$v _{1}$ & $v _{2}$ & $v _{3}$ &  \\ \hline
0 & 1 & 0 & 1594.59 \\ \hline
1 & 0 & 0 & 3656.65 \\ \hline
0 & 0 & 1 & 3755.79 \\ \hline
0 & 2 & 0 & 3151.40 \\ \hline
0 & 1 & 1 & 5332.00 \\ \hline
0 & 2 & 1 & 6874.00 \\ \hline
1 & 0 & 1 & 7251.60 \\ \hline
1 & 1 & 1 & 8807.05 \\ \hline
2 & 0 & 1 & 10613.12 \\ \hline
0 & 0 & 3 & 11032.36 \\ \hline
\end{tabular}
\end{table}

\begin{table}
\centering
\begin{tabular}{S[table-format = 3.2]S[table-format = 3.2]S[table-format = 3.2]S[table-format = 5.2]}
\toprule
\multicolumn{3}{c}{\begin{tabular}[c]{@{}c@{}}Números cuánticos \\[-0.1cm] del estado excitado\end{tabular}} 
&  \multirow{2}{*}{\begin{tabular}[c]{@{}c@{}}\\[-0.95cm]Frecuencias \\[-0.2cm] de absorción \\[-0.2cm] experimentales \\[-0.2cm] (\si{\per\cm})\end{tabular}} \\ \cmidrule{1-3}
$v _{1}$ & $v _{2}$ & $v _{3}$ &  \\ \midrule
0 & 1 & 0 & 1594.59 \\ 
1 & 0 & 0 & 3656.65 \\ 
0 & 0 & 1 & 3755.79 \\ 
0 & 2 & 0 & 3151.40 \\ 
0 & 1 & 1 & 5332.00 \\ 
0 & 2 & 1 & 6874.00 \\ 
1 & 0 & 1 & 7251.60 \\ 
1 & 1 & 1 & 8807.05 \\ 
2 & 0 & 1 & 10613.12 \\ 
0 & 0 & 3 & 11032.36 \\ 
\bottomrule
\end{tabular}
\end{table}
\end{document}

enter image description here

It's better not to use the too restrictive [h] float placement specifier.

3
  • You should use \si{\per\cm} instead of \si{\centi\metre^{-1}}. Also, it should be S[table-format = 5.2] in the last column. May 27 '14 at 21:03
  • @SvendTveskæg I've introduced your suggestions to my answer. Thanks. May 27 '14 at 21:27
  • @Gonzalo Medina I appreciate very much the answer. These weeks I have really been trying very hard this solution, but the use of these packages changes the aspect of the rest of the columns of the document, and it turns out to be a complete mess!! Would it be a simplest way to fix (with a command, such as {p}) the first two columns so that the their width results similar to the third column ?
    – DavidC.
    Jun 16 '14 at 17:29

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.