
켜져 있는 savebox
동안에는 치수를 제대로 캡처할 수 없습니다 .tikzexternalize
MWE는 다음과 같습니다.
\documentclass {article}
\RequirePackage {tikz}
\RequirePackage {expl3}
\usetikzlibrary {shapes}
\usetikzlibrary {external}
% Make every {tikzpicture} block as separate *.png image.
\tikzexternalize [prefix = tests/]
\tikzsetfigurename {test_}
\tikzset{export as png/.style={external/system call/.add = {}{; convert -density 300 -resize 800x600 "\image.pdf" "\image.png"}}}
\tikzset{export as png}
\ExplSyntaxOn
\tikzset{external/export~next = false} % This is needed for savebox to work.
\newsavebox \sandbox
\savebox \sandbox
{
\begin {tikzpicture}
\node [ellipse, minimum~size = 10pt] { };
\end {tikzpicture}
}
\dim_const:Nn \c_ellipse_width {\the\wd\sandbox\space}
\dim_const:Nn \c_something {16pt}
\ExplSyntaxOff
\begin {document}
\ExplSyntaxOn
\dim_log:N \c_ellipse_width
\dim_log:N \c_something
\begin {tikzpicture}
\dim_log:N \c_ellipse_width
\dim_log:N \c_something
\node [ellipse, align = center] {\the\c_ellipse_width \\ \the\c_something};
\end {tikzpicture}
\ExplSyntaxOff
\end {document}
다음과 같이 컴파일하면 기본 *.log에 올바른 값이 표시됩니다.
> \c_ellipse_width=10.0pt.
> \c_something=16.0pt.
테스트/test_0.log는 너비를 변경하고 다음을 표시합니다.
> \c_ellipse_width=405.83112pt.
> \c_something=16.0pt.
말할 필요도 없이, 그림은 tests/test_0.png
잘못된 값을 그릴 것입니다.
관련된 코드 부분이 tikzexternalize
주석 처리되면 기본 *.log에 다음이 표시됩니다.
> \c_ellipse_width=10.0pt.
> \c_something=16.0pt.
*.pdf 콘텐츠에는 이 시나리오에서 그려진 올바른 값이 있습니다.
켜져 있는 tikzpicture
동안 치수를 올바르게 측정하려면 어떻게 해야 합니까 ?tikzexternalize
답변1
결과적으로 문제는 tikz 최적화와 관련이 있습니다.
이 문제를 방지하려면 \tikzset{external/optimize = false}
.
해결책:
\documentclass {article}
\RequirePackage {tikz}
\RequirePackage {expl3}
\usetikzlibrary {shapes}
\usetikzlibrary {external}
% Make every {tikzpicture} block as separate *.png image.
\tikzexternalize [prefix = tests/]
\tikzsetfigurename {test_}
\tikzset{export as png/.style={external/system call/.add = {}{; convert -density 300 -resize 800x600 "\image.pdf" "\image.png"}}}
\tikzset{export as png}
\tikzset{external/optimize = false} % <--------------------------------
\ExplSyntaxOn
\tikzset{external/export~next = false} % This is needed for savebox to work.
\newsavebox \sandbox
\savebox \sandbox
{
\begin {tikzpicture}
\node [ellipse, minimum~size = 10pt] { };
\end {tikzpicture}
}
\dim_const:Nn \c_ellipse_width {\the\wd\sandbox\space}
\dim_const:Nn \c_something {16pt}
\ExplSyntaxOff
\begin {document}
\ExplSyntaxOn
\dim_log:N \c_ellipse_width
\dim_log:N \c_something
\begin {tikzpicture}
\dim_log:N \c_ellipse_width
\dim_log:N \c_something
\node [ellipse, align = center] {\the\c_ellipse_width \\ \the\c_something};
\end {tikzpicture}
\ExplSyntaxOff
\end {document}