错误的餐桌摆放

错误的餐桌摆放

我有以下 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}

它会产生输出,如屏幕截图所示: 错误的餐桌摆放 正如您所见,表格的位置并非我想要的水平居中。如何将表格水平居中?

答案1

您的tabular太宽了,不适合放在页面中。

为了解决这个问题,请插入你的tabular内部\resizebox{\linewidth}{!}{....}

梅威瑟:

\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} 

输出:

在此处输入图片描述

附注:使用\centering而不是center表格内部的环境来使内容居中。


正如 Paul Gessler 所建议的,另一种方法是在表格中使用合适的字体大小。对于您来说,\scriptsize这将使您的表格适合页面:

梅威瑟:

\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} 

输出(几乎)与上面的相同。

相关内容