余白を無視してテーブルまたは tikzpicture を水平方向に中央揃えする

余白を無視してテーブルまたは tikzpicture を水平方向に中央揃えする

テーブル、または私の場合は余白を無視して 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} 

ここに画像の説明を入力してください

キャプションを付けたい場合は、 または パッケージの と コマンドを使用できます(内minipageでフロートを使用することはできません)。\captionofcaptioncapt-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} 

ここに画像の説明を入力してください

関連情報