1

I'm getting a bit of a strange output when I code in the following:

Code:

\begin{tabular}{|>{\centering}m{15mm}|>{\centering}m{15mm}|>{\centering}m{15mm}|>{\centering}m{15mm}|>{\centering}m{15mm}|}
\hline
\multicolumn{1}{|c|}{\textbf{Element}}    &   \multicolumn{2}{c|}{\textbf{Local Nodes}}   &   \multicolumn{2}{c|}{\textbf{Global Nodes}}\\
\hline
a & a & a & a & a \\
\end{tabular}\\

The final column of the second row (i.e. the one with the 'a's) is misformatted. Additionally, when I try to add more lines to the table, it likes to add the first entry into the fifth column.

I have a feeling I'm just missing a typo in my code.

For reference, here's the preamble:

\documentclass[letterpaper,12pt]{report}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage[
backend=biber,
style=ieee,
]{biblatex}
\usepackage{csquotes}
\title{\bfseries\sffamily\Huge XX}
\author{\sffamily XX}
\date{\sffamily XX}
\usepackage[left=2.5cm, right=2.5cm, top=2.5cm, bottom=2.5cm]{geometry}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{tocloft}
\usepackage{lipsum}
\renewcommand{\cfttoctitlefont}{\sffamily\Large\bfseries}
\renewcommand{\contentsname}{\Huge \bfseries \sffamily Contents}
\renewcommand{\cftsecleader}{\cftdotfill{\cftdotsep}}
\usepackage{titlesec}
\usepackage{amsmath}
\setlength{\parskip}{10pt}
\setlength{\parindent}{0pt} %This removes the standard indentation from the 
beginning of paragraphs
\titleformat{\chapter}
{\Huge\bfseries\sffamily} % format
{\Huge{\thechapter}\hspace{2mm}}                % label
{0pt}             % sep
{\Huge}           % before-code 
\titleformat{\section}
{\Large\bfseries\sffamily} % format
{\Large{\thesection}\hspace{2mm}}                % label
{0pt}             % sep
{\Large}           % before-code 
\titleformat{\subsection}
{\normalfont\sffamily\large\bfseries}
{\thesubsection}{1em}{}
\titleformat{\subsubsection}
{\normalfont\sffamily\normalsize\bfseries}
{\thesubsubsection}{1em}{} 
\usepackage[font=sf]{caption}
\usepackage{palatino}
\usepackage{fourier}
\usepackage{physics}
\usepackage{array}
\raggedright
\usepackage{subfiles}
\addbibresource{bibliography.bib}

Output Output

1
  • Off-topic but relevant nevertheless: The hyperref package should be loaded last in the preamble of your document. Also: The palatino package is considered deprecated; load the package newpxtext instead. (I see you're also loading the fourier package, presumably for math material. An alternative to fourier would be newpxmath.)
    – Mico
    Aug 10 '17 at 5:48
2

enter image description here

you should add \arraybackslash after \centering at least in the last column:

\begin{tabular}{|*{5}{>{\centering\arraybackslash}m{15mm}|}}
    \hline
\textbf{Element}
    &   \multicolumn{2}{c|}{\textbf{Local Nodes}}
        &   \multicolumn{2}{c|}{\textbf{Global Nodes}}  \\
    \hline
a & a & a & a & a                                       \\
    \hline
\end{tabular}

edit: as Mico suggested in his comment below, you can for simpler table typing define new column type for example as:

newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}

and then use it as

\begin{tabular}{|*{5}{M{15mm}|}}

(in case of equal width of columns) or for example

\begin{tabular}{|M{15mm}| M{20mm}| M{20mm}| M{10mm}| M{10mm}|}

when their width are different.

2
  • @MosheHollander, you can accept answer by clicking on check mark on the top left side of answer :). happy tex-ing!
    – Zarko
    Aug 10 '17 at 3:56
  • +1. Since the same column type -- >{\centering\arraybackslash}m -- is used 5 times -- you may want to advise the OP to set up a newcolumn type, called (say) M, as follows: \newcolumntype{M}[1]{{#1}}. Then, the header of the tabular environment may be written more succinctly as \begin{tabular}{|*{5}{M{15mm}|}}. :-)
    – Mico
    Aug 10 '17 at 5:38

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.