Vertically and horizontally centering a matrix bigger than margins
This question is a follow-up on a previous question: positioning of a
matrix bigger than margins
That question dealt with positioning a pgf matrix that exceeded the
horizontal margins of the page (although I imagine this works for floats
as well?), and both answers provide a solution to the problem.
However, none of those solutions work if the matrix is bigger than the
margins both horizontally and vertically.
How can I make sure that a matrix that is (slightly) too big for the
margins is centered on the page, both vertically and horizontally?
It seems to me that, out of the answers provided in the previous question,
the one based on stackengine might be more up to the task (that's why I
chose to use that one below), but this may well not be the case, and of
course I'm open to all sorts of suggestions.
This is a sample document using the stackengine solution:
\documentclass{article}
\usepackage{tikz}
\usepackage{pgf}
\usetikzlibrary{matrix}
\usepackage{stackengine}
\newcommand\zerowidth[2][c]{\stackengine{0pt}{}{#2}{O}{#1}{F}{T}{L}}
\begin{document}
\newsavebox\toowide
\setbox0=\hbox{%
\begin{tikzpicture}
\matrix [
matrix of nodes,
nodes={
text depth=4em,
text height=5em,
minimum width=10em,
draw
},
row sep=-\pgflinewidth,
column sep=-\pgflinewidth,
]
{
A & B & C & D \\
A & B & C & D \\
A & B & C & D \\
A & B & C & D \\
A & B & C & D \\
A & B & C & D \\
A & B & C & D \\
A & B & C & D \\
};
\end{tikzpicture}
\unskip}
\sbox\toowide{\box0}
\centering\zerowidth{\usebox{\toowide}}
\noindent\rule{\textwidth}{1ex}
\end{document}
No comments:
Post a Comment