1

I have following MWE:

\documentclass[12pt,a4paper]{article}

\usepackage[utf8]{inputenc}
\usepackage[color=red,opacity=0.1,contents={}]{background}
\usepackage{hyperref}
\usepackage{indentfirst}
\usepackage{caption}
\usepackage{listings}
\usepackage[listingsutf8]{tcolorbox}
\usepackage{tcolorbox}
\usepackage[slovene]{babel}
\usepackage{titlesec}
\usepackage{float}
\usepackage{pifont}

\setcounter{secnumdepth}{4}

\titleformat{\paragraph}
{\normalfont\normalsize\bfseries}{\theparagraph}{1em}{}
\titlespacing*{\paragraph}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}

\author{Marko Frelih \\ Company \\ \texttt{email}}
\title{Installation manual}
\date{Ljubljana, Marec 2015}

\begin{document}
\maketitle
\thispagestyle{empty}
\pagebreak
\clearpage
\pagenumbering{arabic}

\AddEverypageHook{
  \ifnum\value{page}<1\relax
  \else
  \backgroundsetup{contents={ZAUPNO}}
  \fi
\BgMaterial
}

\section{Zgodovina dokumenta}
\begin{table}[htbp]
    \begin{center}
        \begin{tabular}{|c|c|c|c|}
            \hline Verzija & Avtor & Datum & Opis \\
            \hline 0.1 & texttexttexttexttexttexttext & 04/03/2015 & texttexttexttexttexttexttexttexttexttext\\
            \hline 0.2 & texttexttexttexttexttexttext & 05/03/2015 & texttexttexttexttexttexttexttexttexttext\\
            \hline 0.3 & texttexttexttexttexttexttext & 05/03/2015 & texttexttexttexttexttexttexttexttexttext\\
            \hline 0.4 & texttexttexttexttexttexttext & 05/03/2015 & texttexttexttexttexttexttexttexttexttext\\
            \hline 0.5 & texttexttexttexttexttexttext & 06/03/2015 & texttexttexttexttexttexttexttexttexttext\\
            \hline 0.6 & texttexttexttexttexttexttext & 08/03/2015 & texttexttexttexttexttexttexttexttexttext\\
            \hline 0.7 & texttexttexttexttexttexttext & 11/03/2015 & texttexttexttexttexttexttexttexttexttext\\
            \hline 0.8 & texttexttexttexttexttexttext & 20/03/2015 & texttexttexttexttexttexttexttexttexttext\\
            \hline 0.9 & texttexttexttexttexttexttext & 21/03/2015 & texttexttexttexttexttexttexttexttexttext\\
            \hline
        \end{tabular}
    \end{center}
    \caption{Zgodovina dokumenta}\label{tblZgodovinaDokumenta}
\end{table}
\pagebreak

\end{document}

It produces output, shown as screenshot: Wrong table placement As you can see, the table is not position as I would like, to be horizontaly centered. How do I horizontally center the table?

KernelPanic
  • 573
  • 1
  • 6
  • 16

1 Answers1

4

Your tabular is too wide and doesn't fit in the page.

To overcome this, insert your tabular inside \resizebox{\linewidth}{!}{....}.

MWE:

\documentclass[12pt,a4paper]{article}

\usepackage[utf8]{inputenc}
\usepackage[color=red,opacity=0.1,contents={}]{background}
\usepackage{hyperref}
\usepackage{indentfirst}
\usepackage{caption}
\usepackage{listings}
\usepackage[listingsutf8]{tcolorbox}
\usepackage{tcolorbox}
\usepackage[slovene]{babel}
\usepackage{titlesec}
\usepackage{float}
\usepackage{pifont}

\setcounter{secnumdepth}{4}

\titleformat{\paragraph}
{\normalfont\normalsize\bfseries}{\theparagraph}{1em}{}
\titlespacing*{\paragraph}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}

\author{Marko Frelih \\ Company \\ \texttt{email}}
\title{Installation manual}
\date{Ljubljana, Marec 2015}

\begin{document}
\maketitle
\thispagestyle{empty}
\pagebreak
\clearpage
\pagenumbering{arabic}

\AddEverypageHook{
  \ifnum\value{page}<1\relax
  \else
  \backgroundsetup{contents={ZAUPNO}}
  \fi
\BgMaterial
}

\section{Zgodovina dokumenta}
\begin{table}[htbp]
\centering
\resizebox{\linewidth}{!}{%
        \begin{tabular}{|c|c|c|c|}
            \hline Verzija & Avtor & Datum & Opis \\
            \hline 0.1 & texttexttexttexttexttexttext & 04/03/2015 & texttexttexttexttexttexttexttexttexttext\\
            \hline 0.2 & texttexttexttexttexttexttext & 05/03/2015 & texttexttexttexttexttexttexttexttexttext\\
            \hline 0.3 & texttexttexttexttexttexttext & 05/03/2015 & texttexttexttexttexttexttexttexttexttext\\
            \hline 0.4 & texttexttexttexttexttexttext & 05/03/2015 & texttexttexttexttexttexttexttexttexttext\\
            \hline 0.5 & texttexttexttexttexttexttext & 06/03/2015 & texttexttexttexttexttexttexttexttexttext\\
            \hline 0.6 & texttexttexttexttexttexttext & 08/03/2015 & texttexttexttexttexttexttexttexttexttext\\
            \hline 0.7 & texttexttexttexttexttexttext & 11/03/2015 & texttexttexttexttexttexttexttexttexttext\\
            \hline 0.8 & texttexttexttexttexttexttext & 20/03/2015 & texttexttexttexttexttexttexttexttexttext\\
            \hline 0.9 & texttexttexttexttexttexttext & 21/03/2015 & texttexttexttexttexttexttexttexttexttext\\
            \hline
        \end{tabular}%
}
    \caption{Zgodovina dokumenta}\label{tblZgodovinaDokumenta}
\end{table}
\pagebreak

\end{document} 

Output:

enter image description here

As a side note, use \centering instead of the center environment inside the table to center its contents.


As Paul Gessler suggests, another method is to use a suitable font size inside your table. In your case, \scriptsize will make your table fit in the page:

MWE:

\documentclass[12pt,a4paper]{article}

\usepackage[utf8]{inputenc}
\usepackage[color=red,opacity=0.1,contents={}]{background}
\usepackage{hyperref}
\usepackage{indentfirst}
\usepackage{caption}
\usepackage{listings}
\usepackage[listingsutf8]{tcolorbox}
\usepackage{tcolorbox}
\usepackage[slovene]{babel}
\usepackage{titlesec}
\usepackage{float}
\usepackage{pifont}

\setcounter{secnumdepth}{4}

\titleformat{\paragraph}
{\normalfont\normalsize\bfseries}{\theparagraph}{1em}{}
\titlespacing*{\paragraph}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}

\author{Marko Frelih \\ Company \\ \texttt{email}}
\title{Installation manual}
\date{Ljubljana, Marec 2015}

\begin{document}
\maketitle
\thispagestyle{empty}
\pagebreak
\clearpage
\pagenumbering{arabic}

\AddEverypageHook{
  \ifnum\value{page}<1\relax
  \else
  \backgroundsetup{contents={ZAUPNO}}
  \fi
\BgMaterial
}

\section{Zgodovina dokumenta}
\begin{table}[htbp]
\centering
\scriptsize
        \begin{tabular}{|c|c|c|c|}
            \hline Verzija & Avtor & Datum & Opis \\
            \hline 0.1 & texttexttexttexttexttexttext & 04/03/2015 & texttexttexttexttexttexttexttexttexttext\\
            \hline 0.2 & texttexttexttexttexttexttext & 05/03/2015 & texttexttexttexttexttexttexttexttexttext\\
            \hline 0.3 & texttexttexttexttexttexttext & 05/03/2015 & texttexttexttexttexttexttexttexttexttext\\
            \hline 0.4 & texttexttexttexttexttexttext & 05/03/2015 & texttexttexttexttexttexttexttexttexttext\\
            \hline 0.5 & texttexttexttexttexttexttext & 06/03/2015 & texttexttexttexttexttexttexttexttexttext\\
            \hline 0.6 & texttexttexttexttexttexttext & 08/03/2015 & texttexttexttexttexttexttexttexttexttext\\
            \hline 0.7 & texttexttexttexttexttexttext & 11/03/2015 & texttexttexttexttexttexttexttexttexttext\\
            \hline 0.8 & texttexttexttexttexttexttext & 20/03/2015 & texttexttexttexttexttexttexttexttexttext\\
            \hline 0.9 & texttexttexttexttexttexttext & 21/03/2015 & texttexttexttexttexttexttexttexttexttext\\
            \hline
        \end{tabular}
    \caption{Zgodovina dokumenta}\label{tblZgodovinaDokumenta}
\end{table}
\pagebreak

\end{document} 

The output is (almost) the same as above.

karlkoeller
  • 124,410
  • 2
    If you're going to go this route, much better would be to just pick a font size that fits, i.e., \small, \footnotesize, etc., rather than introducing arbitrary scaling with \resizebox. – Paul Gessler Mar 21 '15 at 13:41