我正在尝试运行以下命令
\documentclass{article}
%% Margins Packages %%
\usepackage[margin=0cm]{geometry}
%% Graphics Packages %%
\usepackage{tikz}
%% Timeline Packages %%
\usetikzlibrary{calc,matrix}
%% Graphics Path %%
\graphicspath{{../Pictures/}}
%% Custom Commands %%
\newcommand\circularpicture[7]{
\begin{tikzpicture}
\node[
circle,
draw=#1,
line width=#2,
inner sep=#3,
path picture={
\node at (#4, #5) {
\includegraphics[width=#6]{#7}
};
}] (A) {};
\end{tikzpicture}
}
\begin{document}
\noindent\fcolorbox{black}{black}{
\begin{minipage}[]{0.40\textwidth}
\textcolor{white}{
\begin{center}
\fontsize{25pt}{20pt}\selectfont Name\\
\fontsize{15pt}{20pt}\selectfont Subject \\
\vspace*{20.0pt}
\circularpicture{white, 1mm, 1.2cm, 0, -0.8cm, 5cm, cover-picture}
\end{center}
}
\end{minipage}
}
\end{document}
但我收到以下错误。
line 45: Paragraph ended before \@textcolor was complete. }
line 45: Argument of \circularpicture has an extra }. }
line 45: Paragraph ended before \circularpicture was complete. }
line 45: Extra }, or forgotten \endgroup. }
但是,如果我直接将命令代入文档中,它可以很好地编译。
\documentclass{article}
%% Margins Packages %%
\usepackage[margin=0cm]{geometry}
%% Graphics Packages %%
\usepackage{tikz}
%% Timeline Packages %%
\usetikzlibrary{calc,matrix}
%% Graphics Path %%
\graphicspath{{../Pictures/}}
\begin{document}
\noindent\fcolorbox{black}{black}{
\begin{minipage}[]{0.40\textwidth}
\textcolor{white}{
\begin{center}
\fontsize{25pt}{20pt}\selectfont Ivor Denham-Dyson\\
\fontsize{15pt}{20pt}\selectfont Data Science and Software
\\
\vspace*{20.0pt}
\begin{tikzpicture}
\node[
circle,
draw=white,
line width=1mm,
inner sep=1.2cm,
path picture={
\node at (0cm, -0.8cm) {
\includegraphics[width=5cm]{cover-picture}
};
}] (A) {};
\end{tikzpicture}
\end{center}
}
\end{minipage}
}
\end{document}
我对命令还不熟悉,不知道为什么?
答案1
当你这样做
\newcommand{\foo}[7]{...}
TeX 期望调用如下
\foo{one}{two}{three}{four}{five}{six}{seven}
并不是
\foo{one,two,three,four,five,six,seven}
这是您的代码的新版本,它也经过了简化并且进行了各种修复:
%
字符用于掩盖会在输出中产生不需要的空格的结束行;fix-cm
已加载以启用任意字体大小;\fontsize
具有合适的基线跳跃值以更好地控制间距;与整体相比,
\textcolor{white}{...}
在内容开头声明白色更加简单\fcolorbox
;而不是
center
,最好声明\centering
。
\RequirePackage{fix-cm}
\documentclass{article}
%% Graphics Packages %%
\usepackage{tikz}
%% Timeline Packages %%
\usetikzlibrary{calc,matrix}
%% Custom Commands %%
\newcommand\circularpicture[7]{% <--- don't forget
\begin{tikzpicture}
\node[
circle,
draw=#1,
line width=#2,
inner sep=#3,
path picture={
\node at (#4, #5) {
\includegraphics[width=#6]{#7}
};
}] (A) {};
\end{tikzpicture}% <--- don't forget
}
\begin{document}
\fcolorbox{black}{black}{% <--- don't forget
\color{white}% <--- don't forget
\begin{minipage}[]{0.40\textwidth}
\centering
\fontsize{25pt}{32pt}\selectfont Name\\
\fontsize{15pt}{18pt}\selectfont Subject\\
\vspace*{20pt}
\circularpicture{white}{1mm}{1.2cm}{0}{-0.8cm}{5cm}{example-image}
\end{minipage}% <--- don't forget
}
\end{document}