在 Texmaker latex 中使用 \begin{center} 时表格未居中

在 Texmaker latex 中使用 \begin{center} 时表格未居中

我正在使用的这 2 个表格有问题\begin{center} ... \end{center},但表格不在 pdf 中居中。有人知道可能是什么问题吗?

\begin{table} [!ht]
\begin{center}
 \begin{tabular}{| c | c | c | c |} 
 \hline
Cost & Scenario 1: 100kWh & Scenario 2: 75kWh & Scenario 3: 50kWh \\[0.5ex] 
\hline \hline
CS1 revenues & 33,653 € & 33,645 € & 33,668 € \\ %[0.5ex] 
\hline
CS2 revenues & 33,712 € & 33,714 € & 33,685 € \\
 \hline
Load revenues & 5,400 € & 5,400 € & 5,400 € \\
 \hline
Export of electricity & 15 € & 43 € & 0 € \\
 \hline  
PV revenues & 5113 € & 5113 € & 5113 € \\
 \hline  
CHP revenues & 3215 € & 3215 € & 3215 €  \\
 \hline
Total operating income & 81,108 € & 81,130 € & 81,081 € \\
 \hline \hline   
Imported electricity & 24,604 € & 24,864 € & 21,269 €  \\ %[0.5ex] 
\hline
Natural gas cost & 3,700 € & 3,700 € & 3,700 € \\
 \hline
Total operating expenditure & 28,304 € & 28,564 € & 24,969 €  \\
 \hline 
Operating cost & -52,804 € & -52,566 € & -56,112 € \\
 \hline \hline 
\end{tabular}
\caption{Operating cost calculation}
 \label{Total annual cost}
\end{center}
\end{table}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Total Net Present Cost}
Net present cost is an economic tool to represent the life-cycle cost of a system. The total NPC calculates all the costs and revenues that occur within the project lifetime with future operating cost considering the interest rate. \\ 
%The total NPC cost has as equation: \\
% NPC= sum (annual cost Can,t for t from 0 to 9 years)+ Capital cost
%\begin{equation}
%\LC = \sum_{\myy=0}^{\lifetime}{\NPC{0} - \rp} + \ct
%\end{equation}
In table \ref{Project lifetime parameters}, the capital and maintenance cost, the project lifetime which is equal to the term loan, the operating cost and yearly repayment for the bank has been displayed to be used later. \\
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{table} [!ht]
\begin{center}
 \begin{tabular}{| c | c | c | c |} 
 \hline
Parameter & Scenario 1: 100kWh & Scenario 2: 75kWh & Scenario 3: 50kWh  \\[0.5ex] %$\ct$
\hline 
Capital and maintenance cost & 178,548 € & 163,548 € & 148,548 € \\[0.5ex] %$\ct$
\hline 
Interest rate  & 2\% & 2\% & 2\% \\ [0.5ex] %$\interest$
\hline
Project lifetime  & 10 years & 10 years & 10 years \\ %$\lifetime$
 \hline
Term loan  & 10 years & 10 years & 10 years \\ %$\lifetime$
 \hline
Yearly repayment for the bank & 17,855 € & 16,355 € & 14,855 € \\ % $\rb$
 \hline 
\end{tabular}
\caption{Project lifetime parameters}
 \label{Project lifetime parameters}
\end{center}
\end{table}

答案1

  • 请考虑您问题下方的所有评论。您仍然可以编辑您的问题并添加遗漏的信息。
  • 当(且仅当)表格的宽度小于时,命令\centering或环境将表格置于文本区域的中心,而不是页面的中心。center\textwidth
  • 如果表格比\textwidth(似乎是您的情况)宽,表格将从左文本边框开始并从右文本边框溢出,无论您分别使用命令\centering还是center环境。
  • 您的问题实际上是重复的这个问题

作为寻找问题解决方案的起点,可以使用以下 MWE(最小工作示例,我们对您的期望)示例,其中您的表格可以是:

\documentclass{article}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\usepackage{siunitx}
\usepackage{makecell}
\setcellgapes{3pt}

\begin{document}
    \begin{table}[ht]
    \makegapedcells
    \centering
 \begin{tabular}{| l | c | c | c |}
    \hline
Parameter   &   \makecell{Scenario 1:\\ \SI{100}{\kWh}} 
                &   \makecell{Scenario 2:\\ \SI{75}{\kWh}} 
                    &   \makecell{Scenario 3:\\ \SI{50}{\kWh}}    \\
    \hline
Capital and maintenance cost 
            & 178,548 €     & 163,548 €     & 148,548 €         \\
    \hline
Interest rate  
            & \SI{2}{\%}    & \SI{2}{\%}    & \SI{2}{\%}        \\ 
    \hline
Project lifetime  
            & 10 years      & 10 years      & 10 years          \\ 
    \hline
Term loan  & 10 years       & 10 years      & 10 years          \\ 
    \hline
Yearly repayment for the bank 
            & 17,855 €      & 16,355 €      & 14,855 €          \\ 
    \hline
\end{tabular}
\caption{Project lifetime parameters}
\label{Project lifetime parameters}
    \end{table}
\end{document}

上面的 MWE 使用了以下包:

  • siunitx对于写作单位
  • makecell对于具有多行文本的单元格(用于列标题)以及在单元格内容周围添加垂直空间:空间由\setcellgapes{<size>}宏设置和激活\makegapedcells

在此处输入图片描述

(红线显示页面布局)

答案2

您的表格太宽。原因之一是数据重复,例如“Scenario”重复了三次,并且第一个表格的大多数单元格中都有 €。

我对更好地呈现您的表格提出了一些建议:所有重复都包含在几个地方,并siunitx使用设施来统一打印数字。

我还删除了大部分规则,特别是那些毫无用处的垂直规则。我还用官方符号替换了丑陋的欧元符号。

假设您要在其中发表论文的期刊要求您避免使用逗号分隔符来分隔千位数字,但要使用较短的空格。如果您已使用 准备了文档siunitx,则只需更改即可满足要求一条线的代码。

不要使用center,但\centering如下所示。另外,为了结束一个段落,一个空行就足够了,并且\\会产生虚假警告。

\documentclass{article}
\usepackage{booktabs,eurosym,siunitx}

\sisetup{group-separator={,}}

\DeclareUnicodeCharacter{20AC}{\euro}

\begin{document}

\begin{table} [!htp]
\centering

\sisetup{group-four-digits} % local setting

\begin{tabular}{l *{3}{S[table-format=-5.0]}}
\toprule
\multicolumn{1}{c}{Cost (€)} & \multicolumn{3}{c}{Scenarios} \\
\cmidrule{2-4}
& {1: \SI{100}{kWh}} & {2: \SI{75}{kWh}} & {3: \SI{50}{kWh}} \\
\midrule
CS1 revenues                &  33653 &  33645 &  33668 \\
CS2 revenues                &  33712 &  33714 &  33685 \\
Load revenues               &   5400 &   5400 &   5400 \\
Export of electricity       &     15 &     43 &      0 \\
PV revenues                 &   5113 &   5113 &   5113 \\
CHP revenues                &   3215 &   3215 &   3215 \\
Total operating income      &  81108 &  81130 &  81081 \\
\midrule
Imported electricity        &  24604 &  24864 &  21269 \\
Natural gas cost            &   3700 &   3700 &   3700 \\
Total operating expenditure &  28304 &  28564 &  24969 \\
Operating cost              & -52804 & -52566 & -56112 \\
\bottomrule
\end{tabular}

\caption{Operating cost calculation}
 \label{Total annual cost}

\end{table}

\subsection{Total Net Present Cost}

Net present cost is an economic tool to represent the life-cycle cost of 
a system. The total NPC calculates all the costs and revenues that occur 
within the project lifetime with future operating cost considering the 
interest rate.

In table \ref{Project lifetime parameters}, the capital and maintenance 
cost, the project lifetime which is equal to the term loan, the operating 
cost and yearly repayment for the bank has been displayed to be used later.

\begin{table} [!htp]
\centering

\begin{tabular}{l c c c} 
\toprule
\multicolumn{1}{c}{Parameter} & \multicolumn{3}{c}{Scenarios} \\
\cmidrule{2-4}
& 1: \SI{100}{kWh} & 2: \SI{75}{kWh} & 3: \SI{50}{kWh}  \\
\midrule
Capital and maintenance cost (€) & \num{178548} & \num{163548} & \num{148548} \\
Interest rate  & 2\% & 2\% & 2\% \\
Project lifetime (years)  & 10 & 10 & 10 \\
Term loan (years) & 10 & 10 & 10 \\
Yearly repayment for the bank (€) & \num{17855} & \num{16355} & \num{14855} \\
\bottomrule
\end{tabular}

\caption{Project lifetime parameters}
 \label{Project lifetime parameters}

\end{table}

\end{document}

在此处输入图片描述

如果我注释掉该\sisetup{group-separator={,}}行,输出将变为

在此处输入图片描述

因此,您会发现以“抽象”形式输入数字以便根据个人喜好进行后续处理的便利性。

相关内容