如何按比例改变所有线宽(例如改变两倍)?
下面是一个 MWE 来说明这个问题:
\documentclass[tikz, border = 1cm]{standalone}
%some magic line which changes all the line width by a factor of two
\begin{document}
\begin{tikzpicture}
\draw[thin] (0,0) -- ++(2,0);
\draw (0,1) -- ++(2,0);
\draw[thick] (0,2) -- ++(2,0);
\end{tikzpicture}
\end{document}
这与pgfplots - 如何将所有默认线宽/厚度值设置为某个值?因为我不想只改变一条线的宽度。
默认线宽不应改变。
答案1
线宽thin
、thick
等定义如下(取自这里):
\tikzset{
ultra thin/.style= {line width=0.1pt},
very thin/.style= {line width=0.2pt},
thin/.style= {line width=0.4pt},
semithick/.style= {line width=0.6pt},
thick/.style= {line width=0.8pt},
very thick/.style= {line width=1.2pt},
ultra thick/.style={line width=1.6pt}
}
因此,我建议用给定长度变量(例如)的倍数来替换此定义\mylinewidth
。然后,您可以全局或局部更改值\mylinewidth
,并且具有这些选项的线条将调整其宽度。
示例(请注意下面的评论):
\documentclass{article}
\usepackage{tikz}
\newlength\mylinewidth
\setlength\mylinewidth{0.4pt}
\tikzset{
ultra thin/.style= {line width=0.25\mylinewidth},
very thin/.style= {line width=0.5\mylinewidth},
thin/.style= {line width=\mylinewidth},
semithick/.style= {line width=1.5\mylinewidth},
thick/.style= {line width=2\mylinewidth},
very thick/.style= {line width=3\mylinewidth},
ultra thick/.style={line width=4\mylinewidth},
every picture/.style={semithick}
}
\begin{document}
\begin{tikzpicture}
\draw[very thin] (0,0) -- ++(2,0);
\draw (0,1) -- ++(2,0);
\draw[very thick] (0,2) -- ++(2,0);
\end{tikzpicture}
\hspace{1cm}
\setlength\mylinewidth{1pt}
\begin{tikzpicture}
\draw[very thin] (0,0) -- ++(2,0);
\draw (0,1) -- ++(2,0);
\draw[very thick] (0,2) -- ++(2,0);
\end{tikzpicture}
\end{document}
注意:在此示例中,我使用了semithick
默认线宽,因为在我看来,这看起来是正确的。当然,您也可以使用标准默认值,即every picture/.style={thin}
。