如何將參數「儲存」到 \begin{tikzpicture}

如何將參數「儲存」到 \begin{tikzpicture}

我是使用 tikz 的新手,每次插入圖表時,我都會貼到以下區塊中(我正在輸入實體作業,因此我必須繪製的圖片類型幾乎總是相同的):

\begin{tikzpicture}[
    force/.style={>=latex,draw=blue,fill=blue},
    axis/.style={densely dashed,gray,font=\small},
    M/.style={rectangle,draw,fill=lightgray,minimum size=0.5cm,thin},
    m/.style={rectangle,draw=black,fill=lightgray,minimum size=0.3cm,thin},
    plane/.style={draw=black,fill=blue!10},
    string/.style={draw=red, thick},
    pulley/.style={thick},
]

我想縮短我必須輸入的命令。我的理解是,這些是“樣式”,並且有一種方法可以做到這一點,但我使用 tikzset 的嘗試只產生了令人困惑的結果。 (基本上,我在 tikzset 中編寫的內容在文件的第一頁上以文字形式輸出)我將不勝感激。

答案1

使用\tikzset

\documentclass{article}
\usepackage{tikz}
\tikzset{    
    force/.style={>=latex,draw=blue,fill=blue},
    axis/.style={densely dashed,gray,font=\small},
    M/.style={rectangle,draw,fill=lightgray,minimum size=0.5cm,thin},
    m/.style={rectangle,draw=black,fill=lightgray,minimum size=0.3cm,thin},
    plane/.style={draw=black,fill=blue!10},
    string/.style={draw=red, thick},
    pulley/.style={thick},
}
\begin{document}
\begin{tikzpicture}
\draw[pulley] (0,0) -- (1,0);
% more code here
\end{tikzpicture}
\end{document}

相關內容