如何將表格或在我的情況下將 tikzpicture 水平居中而忽略邊距?我的 tikzpicture 稍微太大,導致它無法正確居中(粘在右邊距中稍微太多,但如果正確居中,它會更少)
我試過了
\makebox[\textwidth][c]{}
但我只是收到一堆錯誤。
答案1
新增ampersand replacement=\&
至tikzpicture
選項並變更&
為tikzpicture
(\&
請參閱部分17.5 關於活動角色的考慮手冊pgf
):
\documentclass{article}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\lipsum[2]
\noindent\makebox[\textwidth]{%
\begin{tikzpicture}[ampersand replacement=\&]
\matrix [matrix of nodes]
{
8 \& 1 \& 6 \& 8 \& 1 \& 6 \& 8 \& 1 \& 6 \& 6 \& 8 \& 1 \& 6 \& 6 \& 8 \& 1 \& 6 \& 6 \& 8 \& 1 \& 6 \& 6 \& 8 \& 1 \& 6 \& 6 \& 8 \& 1 \& 6 \& 6 \& 8 \& 1 \& 6 \& 6 \& 8 \& 1 \& 6 \\
};
\end{tikzpicture}%
}
\end{document}
如果你想要一個標題,你可以使用 aminipage
和或套件\captionof
中的命令(你不能在 a 中使用浮動):caption
capt-of
\makebox
\documentclass{article}
\usepackage{caption}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usepackage{lipsum}
\begin{document}
\lipsum[2]
\noindent\makebox[\textwidth]{%
\begin{minipage}{2\textwidth}
\centering
\begin{tikzpicture}[ampersand replacement=\&]
\matrix [matrix of nodes]
{
8 \& 1 \& 6 \& 8 \& 1 \& 6 \& 8 \& 1 \& 6 \& 6 \& 8 \& 1 \& 6 \& 6 \& 8 \& 1 \& 6 \& 6 \& 8 \& 1 \& 6 \& 6 \& 8 \& 1 \& 6 \& 6 \& 8 \& 1 \& 6 \& 6 \& 8 \& 1 \& 6 \& 6 \& 8 \& 1 \& 6 \\
};
\end{tikzpicture}
\captionof{figure}{Test caption}
\end{minipage}%
}
\end{document}