我有一张包含以下代码的图表。当我编译此代码时,左侧有一个额外的空白区域。为什么会发生这种情况?我该怎么做才能修复它?
\documentclass{standalone}
\usepackage[showframe,pass]{geometry}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\tikzstyle{b} = [rectangle, draw, node distance=2.6cm, text width=6em, text centered, rounded corners, minimum height=8em, minimum width=6em, thick, font=\small, fill=black!10]
\begin{tikzpicture}[auto]
\node [b] (1) {block 1 \\ block 1};
\node [b, right of=1] (2) {block 2 \\ block 2};
\node [b, right of=2] (3) {block 3 \\ block 3};
\node [b, right of=3] (4) {block 4 \\ block 4};
\node [b, right of=4] (5) {block 5 \\ block 5};
\node [b, below = 2mm of 1] (6) {block 6 \\ block 6};
\node [b, below = 2mm of 2] (7) {block 7 \\ block 7};
\node [b, right of=7] (8) {block 8 \\ block 8};
\node [b, right of=8] (9) {block 9 \\ block 9};
\draw[-, thick] (1)--(2)--(3)--(4)--(5);
\draw[-, thick] (2)--(7)--(8)--(9)--(4);
\end{tikzpicture}
\end{document}
它看起来像这样:
答案1
这是声明后的行尾\tikzstyle
。将其移到 之前\begin{document}
。
顺便说一句,\tikzstyle
它已被弃用,并且我将其更改为当前首选的格式。
\documentclass{standalone}
\usepackage[showframe,pass]{geometry}
\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzset{
b/.style = {
rectangle,
draw,
node distance=2.6cm,
text width=6em,
text centered,
rounded corners,
minimum height=8em,
minimum width=6em,
thick,
font=\small,
fill=black!10,
},
}
\begin{document}
\begin{tikzpicture}[auto]
\node [b] (1) {block 1 \\ block 1};
\node [b, right of=1] (2) {block 2 \\ block 2};
\node [b, right of=2] (3) {block 3 \\ block 3};
\node [b, right of=3] (4) {block 4 \\ block 4};
\node [b, right of=4] (5) {block 5 \\ block 5};
\node [b, below = 2mm of 1] (6) {block 6 \\ block 6};
\node [b, below = 2mm of 2] (7) {block 7 \\ block 7};
\node [b, right of=7] (8) {block 8 \\ block 8};
\node [b, right of=8] (9) {block 9 \\ block 9};
\draw[-, thick] (1)--(2)--(3)--(4)--(5);
\draw[-, thick] (2)--(7)--(8)--(9)--(4);
\end{tikzpicture}
\end{document}
答案2
答案3
摆脱导致此问题的换行符(和已弃用的\tikzstyle
)的另一种可能性是将 tikz 样式移到的可选参数中\begin{tikzpicture}
:
\begin{document}
\begin{tikzpicture}[
auto,
b/.style={rectangle, draw, node distance=2.6cm, text width=6em, text centered, rounded corners, minimum height=8em, minimum width=6em, thick, font=\small, fill=black!10},
]
...
答案4
如果您因任何原因无法更改序言,则可以通过在\begin{document}
和\begin{tikzpicture}
之间添加注释来忽略换行符:
\begin{document}%
%
\tikzstyle{b} = [rectangle, draw, node distance=2.6cm, text width=6em, text centered, rounded corners, minimum height=8em, minimum width=6em, thick, font=\small, fill=black!10]%
%
\begin{tikzpicture}[auto]\begin{document}%
...