避免對每個表重複 [hbt] 和 \centering

避免對每個表重複 [hbt] 和 \centering

在我正在編寫的文檔中,我使用了熟悉的[hbt]我的浮動桌的選項,我中心他們。我想避免每次創建表格時都重複這一點。我認為在序言中添加一些內容很容易,以確保每次開始新table環境時都使用這兩個選項?

\documentclass{article}
\begin{document}
\begin{table}[hbt]
\centering
\begin{tabular}{*3{l}}
1 & 2 & 3\\
a & b & c\\
\end{tabular}
\end{table}
\end{document}

答案1

預設圖形位置可以設定為

\makeatletter
\renewcommand\fps@figure{htbp}
\makeatletter

p(不包含在預設值中幾乎總是一個壞主意)

為了居中,您可以將其添加到\@floatboxreset

\makeatletter
\def \@floatboxreset {%
        \reset@font
        \normalsize
        \@setminipage
\centering%<<<<<<<<<<<<<<<<<<<
}
\makeatletter

答案2

float包裹提供一個介面來指定特定浮動的浮動位置

\floatplacement{<type>}{<spec>}

\floatplacement指令重置一類浮點數的預設放置說明符。所以,人們可以使用

\floatplacement{table}{hbt}

來實現你所追求的目標。

答案3

嘗試

\documentclass{article}

\newenvironment{mytable}
{\begin{table}[hbt]
  \centering}
{\end{table}}

\begin{document}

\begin{mytable}
\begin{tabular}{*3{l}}
1 & 2 & 3\\
a & b & c\\
\end{tabular}
\end{mytable}
\end{document}

\end{document}

答案4

結合維爾納的回答這裡有鎖步的回答如何自動將影像居中?,我們可以這樣做:

\documentclass{article}
\usepackage{floatrow} % this automatically centers all floats
    \floatplacement{table}{hbtp} % all tables are given the [hbtp] option
\begin{document}
\begin{table}
\begin{tabular}{*3{l}}
1 & 2 & 3\\
a & b & c\\
\end{tabular}
\end{table}
\end{document}

相關內容