我有一些tikzpicture
为 a4 纸设计的 s,现在应该用在 a0 海报上。图片中的所有坐标都可以使用选项进行缩放scale=4
,但这不会影响线宽。
thin
我可以在整个过程中缩放线宽吗,即使是直接设置的线宽,而不是使用类似 的样式tikzpicture
?图片中包含的文本应该不是以此来缩放。
答案1
这类似于Phelype 的评论(我刚才看到的)但是它使用当前变换矩阵的雅可比矩阵(的平方根)来确定比例因子。
\documentclass{article}
\usepackage{tikz}
% Jacobians have already been used in https://tex.stackexchange.com/q/86897/138900
% https://tex.stackexchange.com/a/496418 and https://tex.stackexchange.com/a/506249/194703
\makeatletter
\tikzset{scale line widths/.style={%
/utils/exec=\pgfgettransformentries{\tmpa}{\tmpb}{\tmpc}{\tmpd}{\tmp}{\tmp}%
\pgfmathsetmacro{\myJacobian}{sqrt(abs(\tmpa*\tmpd-\tmpb*\tmpc))}%
\pgfmathsetlength\pgflinewidth{\myJacobian*0.4pt}%
\def\tikz@semiaddlinewidth##1{\pgfmathsetmacro{\my@lw}{\myJacobian*##1}%
\tikz@addoption{\pgfsetlinewidth{\my@lw pt}}\pgfmathsetlength\pgflinewidth{\my@lw pt}},%
thin}}
\makeatother
\begin{document}
\subsubsection*{Original}
\begin{tikzpicture}
\draw (0,0) rectangle (1,1);
\draw[thick] (0,0) -- (1,1);
\draw[line width=2pt] (0,1) -- (1,0);
\end{tikzpicture}
\subsubsection*{Just scale}
\begin{tikzpicture}[scale=4]
\draw (0,0) rectangle (1,1);
\draw[thick] (0,0) -- (1,1);
\draw[line width=2pt] (0,1) -- (1,0);
\end{tikzpicture}
\subsubsection*{Scale and \texttt{scale line widths}}
\begin{tikzpicture}[scale=4,scale line widths]
\draw (0,0) rectangle (1,1);
\draw[thick] (0,0) -- (1,1);
\draw[line width=2pt] (0,1) -- (1,0);
\typeout{\the\pgflinewidth}
\end{tikzpicture}
\end{document}
(是的,我也看到线连接不太好,但这不是这篇文章的重点。;-)
这是一个本地检索比例因子的版本。
\documentclass{article}
\usepackage{tikz}
% Jacobians have already been used in https://tex.stackexchange.com/q/86897/138900
% https://tex.stackexchange.com/a/496418 and https://tex.stackexchange.com/a/506249/194703
\makeatletter
\tikzset{scale line widths/.style={%
/utils/exec=\def\tikz@semiaddlinewidth##1{%
\pgfgettransformentries{\tmpa}{\tmpb}{\tmpc}{\tmpd}{\tmp}{\tmp}%
\pgfmathsetmacro{\myJacobian}{sqrt(abs(\tmpa*\tmpd-\tmpb*\tmpc))}%
\pgfmathsetlength\pgflinewidth{\myJacobian*0.4pt}%
\pgfmathsetmacro{\my@lw}{\myJacobian*##1}%
\tikz@addoption{\pgfsetlinewidth{\my@lw pt}}\pgfmathsetlength\pgflinewidth{\my@lw pt}},%
thin}}
\makeatother
\begin{document}
\subsubsection*{Original}
\begin{tikzpicture}
\draw (0,0) rectangle (1,1);
\draw[thick] (0,0) -- (0,1);
\draw[line width=2pt] (1,0) -- (1,1);
\begin{scope}[scale=2]
\draw[line width=2pt] (1,0) -- (1,0.5);
\end{scope}
\end{tikzpicture}
\subsubsection*{Just scale}
\begin{tikzpicture}[scale=4]
\draw (0,0) rectangle (1,1);
\draw[thick] (0,0) -- (0,1);
\draw[line width=2pt] (1,0) -- (1,1);
\begin{scope}[scale=2]
\draw[line width=2pt] (1,0) -- (1,0.5);
\end{scope}
\end{tikzpicture}
\subsubsection*{Scale and \texttt{scale line widths}}
\begin{tikzpicture}[scale=4,scale line widths]
\draw (0,0) rectangle (1,1);
\draw[thick] (0,0) -- (0,1);
\draw[line width=2pt] (1,0) -- (1,1);
\begin{scope}[scale=2]
\draw[line width=2pt] (1,0) -- (1,0.5);
\end{scope}
\end{tikzpicture}
\end{document}