有没有办法将这个 circuitikz 导出为 PDF?
我使用了 tikzpicture,但它剪切了右侧的部分图像。这可能是由于 tikz 和 circuitikz 之间不兼容。
请注意,PDF 大小应与图像大小相同,因此请不要建议编译并导出整个 PDF 页面。
\documentclass[]{article}
\usepackage{circuitikz}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{backgrounds}
\usetikzlibrary{external}
\tikzexternalize
\begin{document}
\begin{tikzpicture}
\centering
\begin{circuitikz}
\draw (0,0) node (N5){}
to [short,o-](2,0)
to[short,*-](4,0)
to[D](4,2)
to[D](4,4)
to[short,-*](2,4) node (N1){}
to[short,-o](0,4) node (O){};
\draw (4,0)
to[short,*-](8,0)
to[D](8,2)
to[D](8,4)
to[short,-*](4,4);
\draw (2,0)
to[Tnpn,n=q2](2,2) node(N2){}
to[Tnpn,n=q1](2,4);
\draw (8,0)
to[short,*-](10,0) node(N4){}
to[Tnpn,n=q4,mirror](10,2)
to[Tnpn,n=q3,mirror](10,4)
to[short,-*](8,4);
\draw
(q1.B) to[short,-o](1,3) node[left]{$Q_1$}
(q2.B) to[short,-o](1,1) node[left]{$Q_2$}
(q3.B) to[short,-o](11,3) node[right]{$Q_3$}
(q4.B) to[short,-o](11,1) node[right]{$Q_4$};
\draw (2,2) to[short,*-*](4,2) to[Telmech=M](8,2) to[short,*-*](10,2) node(N3){};
% adding current
\begin{scope}[on background layer, very thick,decoration = {
markings,
mark = at position 0.05 with {\arrow{>}}}
]
\draw[line width = 3pt, red!40, postaction = {decorate}] (O.north)
-- node[above, red]{$i$} (N1.north east) |- (N3.north west) |-
(N5.north);
\end{scope}
% adding voltage
\draw[line width = 3pt, red!40, ->] (N5) to[out = 150, in = 210]
(O) node[left, red]{$V$};
\end{circuitikz}
\end{tikzpicture}
\end{document}
答案1
在我看来,问题在于产生的边界框tikzpicture
不兼容。您可以使用以下方法修复此问题\useasboundingbox
:
\documentclass{article}
\usepackage{circuitikz}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{backgrounds}
\usetikzlibrary{external}
\tikzexternalize
\begin{document}
\begin{tikzpicture}% circuitikz is also a tikzpicture
% \begin{circuitikz}% but only tikzpicture is externalized.
\draw (0,0) node (N5){}
to [short,o-](2,0)
to[short,*-](4,0)
to[D](4,2)
to[D](4,4)
to[short,-*](2,4) node (N1){}
to[short,-o](0,4) node (O){};
\draw (4,0)
to[short,*-](8,0)
to[D](8,2)
to[D](8,4)
to[short,-*](4,4);
\draw (2,0)
to[Tnpn,n=q2](2,2) node(N2){}
to[Tnpn,n=q1](2,4);
\draw (8,0)
to[short,*-](10,0) node(N4){}
to[Tnpn,n=q4,mirror](10,2)
to[Tnpn,n=q3,mirror](10,4)
to[short,-*](8,4);
\draw
(q1.B) to[short,-o](1,3) node[left]{$Q_1$}
(q2.B) to[short,-o](1,1) node[left]{$Q_2$}
(q3.B) to[short,-o](11,3) node[right]{$Q_3$}
(q4.B) to[short,-o](11,1) node[right]{$Q_4$};
\draw (2,2) to[short,*-*](4,2) to[Telmech=M](8,2) to[short,*-*](10,2) node(N3){};
% adding current
\begin{scope}[on background layer, very thick,decoration = {
markings,
mark = at position 0.05 with {\arrow{>}}}
]
\draw[line width = 3pt, red!40, postaction = {decorate}] (O.north)
-- node[above, red]{$i$} (N1.north east) |- (N3.north west) |-
(N5.north);
\end{scope}
% adding voltage
\draw[line width = 3pt, red!40, ->] (N5) to[out = 150, in = 210]
(O) node[left, red]{$V$};
\useasboundingbox(0,0) rectangle (12,4);% not needed any longer after commenting circuitikz but sometimes useful
% \end{circuitikz}
\end{tikzpicture}
\end{document}
但是,如果您需要仅包含图片的 PDF,那么一个非常简单的解决方案就是使用类standalone
并使用选项进行更正border
:
\documentclass[border={-15mm 3mm 16mm 3mm}]{standalone}
\usepackage{circuitikz}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{backgrounds}
%\usetikzlibrary{external}
%\tikzexternalize
\begin{document}
\begin{tikzpicture}
\begin{circuitikz}
\draw (0,0) node (N5){}
to [short,o-](2,0)
to[short,*-](4,0)
to[D](4,2)
to[D](4,4)
to[short,-*](2,4) node (N1){}
to[short,-o](0,4) node (O){};
\draw (4,0)
to[short,*-](8,0)
to[D](8,2)
to[D](8,4)
to[short,-*](4,4);
\draw (2,0)
to[Tnpn,n=q2](2,2) node(N2){}
to[Tnpn,n=q1](2,4);
\draw (8,0)
to[short,*-](10,0) node(N4){}
to[Tnpn,n=q4,mirror](10,2)
to[Tnpn,n=q3,mirror](10,4)
to[short,-*](8,4);
\draw
(q1.B) to[short,-o](1,3) node[left]{$Q_1$}
(q2.B) to[short,-o](1,1) node[left]{$Q_2$}
(q3.B) to[short,-o](11,3) node[right]{$Q_3$}
(q4.B) to[short,-o](11,1) node[right]{$Q_4$};
\draw (2,2) to[short,*-*](4,2) to[Telmech=M](8,2) to[short,*-*](10,2) node(N3){};
% adding current
\begin{scope}[on background layer, very thick,decoration = {
markings,
mark = at position 0.05 with {\arrow{>}}}
]
\draw[line width = 3pt, red!40, postaction = {decorate}] (O.north)
-- node[above, red]{$i$} (N1.north east) |- (N3.north west) |-
(N5.north);
\end{scope}
% adding voltage
\draw[line width = 3pt, red!40, ->] (N5) to[out = 150, in = 210]
(O) node[left, red]{$V$};
\end{circuitikz}
\end{tikzpicture}
\end{document}
注意:选项tikz
类standalone
还提供了在同一个 PDF 中生成多个 PDF 页面的功能,每个页面一个tikzpicture
。要更改页面之间的选项,您可以使用\standaloneconfig
,例如,
\standaloneconfig{border={3mm 3mm 3mm 3mm}}
在相应的之前tikzpicture
。
一个更简单的建议是使用\documentclass[landscape]{article}
和\pagestyle{empty}
,然后使用pdfcrop
从生成的 PDF 中剪切掉较大的白色边距。使用
pdfcrop --margins 10pt original.pdf
结果original-crop.pdf
几乎和上面显示的相同。
答案2
尽管建议采用独立 PDF由 @cabohah 提议可以说是正确/最好的方法,这里的主要错误是你在筑巢tikzpictures
。 代替
\begin{tikzpicture}
\begin{circuitikz}
...
\end{circuitikz}
\end{tikzpicture}
仅使用
\begin{tikzpicture}
...
\end{tikzpicture}
circuitikz
只是 的别名tikzpicture
;它大多数时候都有效,但是不是当涉及 externalize 时。手册中提到了这一点:
(常见问题解答部分)。虽然我承认它有点隐蔽;但我正在考虑更改\begin{circuitikz}...\end{circuitikz}
手册中的所有内容...
还,请注意,\centering
a 内部除了造成伤害什么也没做。您可能混淆了和tikzpicture
的概念?figure
tikzpicture