
這個問題類似於TikZ \foreach 迴圈與巨集定義列表但在這裡我想要巨集定義的列表爭論。
例如,在以下 MWE 中:
\documentclass{article}
\usepackage{pgffor}
\begin{document}
\begin{description}
\item[Macro without argument]
\newcommand{\macrowithoutargument}{0,...,10}%
\foreach \x in \macrowithoutargument {[\x]}
\item[Macro with argument]
\newcommand{\macrowithargument}[1]{#1,...,10}%
% \foreach \x in \macrowithargument{1} {[\x]}
\end{description}
\end{document}
循環\foreach
:
- 巨集無參數定義清單(
\macrowithoutargument)
就像一個魅力, - 帶有參數定義的巨集清單 (
\macrowithargument{1}
) 失敗。
請注意,我堅持使用TikZ
's\foreach
循環:之前的 MWE 是我在圖片中遇到的問題的最小化TikZ
,我想僅繪製量角器的一部分,並將起始角度和結束角度作為 a 的參數給出巨集。
TikZ
因此我的問題是:的循環列表是否可以\foreach
用帶有參數的巨集來定義?
答案1
我會做
\documentclass{article}
\usepackage{pgffor}
\begin{document}
\begin{description}
\item[Macro without argument]
\newcommand{\macrowithoutargument}{0,...,10}%
\foreach \x in \macrowithoutargument {[\x]}
\item[Macro with argument]
\newcommand{\macrowithargument}[1]{\foreach \x in {#1,...,10}}%
\macrowithargument{1} {[\x]}
\end{description}
\end{document}