我有以下 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}
输出(几乎)与上面的相同。