我正在尝试按以下方式定义自定义环境:
\begin{center}
\begin{rqbox}
\textbf{RQ2.} \emph{
How do source .....?
}
\end{rqbox}
\end{center}
\smallskip
但是,我收到以下编译错误:“未定义的控制序列”\begin{rqbox}
我还发布了rqbox
\newenvironment{rqbox}{\par\begingroup
\setlength{\fboxsep}{5pt}\findlength
\setbox0=\vbox\bgroup\noindent
\hsize=0.95\linewidth
\begin{minipage}{0.95\linewidth}\normalsize}
{\end{minipage}\egroup
% \vspace{6pt}
\textcolor{gray20}{\fboxsep1.5pt\fbox
{\fboxsep5pt\colorbox{gray05}{\normalcolor\box0}}}
% \endgroup\par\addvspace{6pt minus 3pt}\noindent
\endgroup\par\noindent
\normalcolor\ignorespacesafterend}
\let\Examplebox\examplebox
\let\endExamplebox\endexamplebox
你有什么建议吗?
答案1
请始终发布完整的文档,并显示错误。
这里
\documentclass{article}
\newenvironment{rqbox}{\par\begingroup
\setlength{\fboxsep}{5pt}\findlength
\setbox0=\vbox\bgroup\noindent
\hsize=0.95\linewidth
\begin{minipage}{0.95\linewidth}\normalsize}
{\end{minipage}\egroup
% \vspace{6pt}
\textcolor{gray20}{\fboxsep1.5pt\fbox
{\fboxsep5pt\colorbox{gray05}{\normalcolor\box0}}}
% \endgroup\par\addvspace{6pt minus 3pt}\noindent
\endgroup\par\noindent
\normalcolor\ignorespacesafterend}
\let\Examplebox\examplebox
\let\endExamplebox\endexamplebox
\begin{document}
\begin{center}
\begin{rqbox}
\textbf{RQ2.} \emph{
How do source .....?
}
\end{rqbox}
\end{center}
\end{document}
生产
! Undefined control sequence.
\rqbox ... \setlength {\fboxsep }{5pt}\findlength
\setbox 0=\vbox \bgroup \n...
l.22 \begin{rqbox}
?
! Undefined control sequence.
\endrqbox ->\end {minipage}\egroup \textcolor
{gray20}{\fboxsep 1.5pt\fbox {...
l.26 \end{rqbox}
?
我可以猜测\textcolor
需要xcolor
,但我不知道\findlength
注意\end{rqbox}
是发现错误的位置,而不是未定义的命令。
所以运行没有错误
\documentclass{article}
\usepackage{xcolor}
\colorlet{gray20}{red}
\colorlet{gray05}{blue}
\newenvironment{rqbox}{\par\begingroup
\setlength{\fboxsep}{5pt}%\findlength
\setbox0=\vbox\bgroup\noindent
\hsize=0.95\linewidth
\begin{minipage}{0.95\linewidth}\normalsize}
{\end{minipage}\egroup
% \vspace{6pt}
\textcolor{gray20}{\fboxsep1.5pt\fbox
{\fboxsep5pt\colorbox{gray05}{\normalcolor\box0}}}
% \endgroup\par\addvspace{6pt minus 3pt}\noindent
\endgroup%\par\noindent
%\normalcolor
\ignorespacesafterend}
\let\Examplebox\examplebox
\let\endExamplebox\endexamplebox
\begin{document}
\begin{center}
\begin{rqbox}
\textbf{RQ2.} \emph{
How do source .....?
}
\end{rqbox}
\end{center}
\end{document}