使用 enumitem 在书中标记困难练习

使用 enumitem 在书中标记困难练习

在书中,我想用上标 s 标记难懂或困难的部分和练习。我可以使用中的\star宏对如下所示的部分执行此\hard操作。\very hard\section{}

我使用自定义 enumitem 列表环境进行练习,由于某些我无法理解的原因,在和 的输出\exercise\hard之间留了一个空格。有人可以建议如何纠正这个问题吗?Exercise 1.2$\^\star

工作示例:

    \documentclass[12pt]{book}

    \usepackage{xspace}
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % Define new list type for exercises
    % from: http://tex.stackexchange.com/questions/196199/exercise-list-using-enumitem-how-control-indentation-and-labeling-of-sublists
    % by: Daniel Wunderlich
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    \usepackage{enumitem}      % this should be loaded in book.Rnw
    %
    \newlist{Exercises}{enumerate}{2}
    % set list style parameters
    \setlist[Exercises]{%
      label=\textbf{Exercise \thechapter.\arabic*}~,  % Label: Exercise Chapter.exercise
      ref=\thechapter.\arabic*, % References: Chapter.exercise (important!)
      align=left,               % Left align labels
      labelindent=0pt,          % No space betw. margin of list and label
      leftmargin=0pt,           % No space betw. margin of list and following lines
      itemindent=!,             % Indention of item computed automatically
      itemsep=3pt,
    }

    \newcommand{\exercise}{%
      \item\label{lab:\arabic{chapter}.\arabic{Exercisesi}}%      % Append label to item
      \setlist[enumerate, 1]{label=(\alph*),itemsep=0pt}          % Label for subexercises, but only within an exercise
    }
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % Symbols for hard or difficult sections and problems
    \newcommand{\hard}{$^\star$\xspace}
    \newcommand{\veryhard}{$^{\star\star}$\xspace}

    \begin{document}

    \chapter{First chapter}
    \section{First section}
    asdfasfasfs
    \begin{Exercises}
        \exercise What is 2+2?
        \exercise\hard How many angels can fit on the head of a pin?
        \exercise\veryhard Prove the four-color theorem
    \end{Exercises}

    \section{A  hard section\hard}
    asfdAFASFAF

    \section{Very hard section\veryhard}
    asfdAFASFAF


    \end{document}
    % ----------------------------------------------------------------

答案1

labelsep=0pt您在设置列表选项时缺少了什么,但是,此时,当没有发出或时Exercises,您必须添加一个空格。\hard\veryhard

梅威瑟:

\documentclass[12pt]{book}

\usepackage{xspace}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Define new list type for exercises
% from: http://tex.stackexchange.com/questions/196199/exercise-list-using-enumitem-how-control-indentation-and-labeling-of-sublists
% by: Daniel Wunderlich
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\usepackage{enumitem}      % this should be loaded in book.Rnw
%
\newlist{Exercises}{enumerate}{2}
% set list style parameters
\setlist[Exercises]{%
  label=\textbf{Exercise \thechapter.\arabic*},  % Label: Exercise Chapter.exercise
  ref=\thechapter.\arabic*, % References: Chapter.exercise (important!)
  align=left,               % Left align labels
  labelindent=0pt,          % No space betw. margin of list and label
  leftmargin=0pt,           % No space betw. margin of list and following lines
  itemindent=!,             % Indention of item computed automatically
  itemsep=3pt,
  labelsep=0pt,
}

\newcommand{\exercise}{%
  \item\label{lab:\arabic{chapter}.\arabic{Exercisesi}}%      % Append label to item
  \setlist[enumerate, 1]{label=(\alph*),itemsep=0pt}          % Label for subexercises, but only within an exercise
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Symbols for hard or difficult sections and problems
\newcommand{\hard}{$^\star$\xspace}
\newcommand{\veryhard}{$^{\star\star}$\xspace}

\begin{document}

\chapter{First chapter}
\section{First section}
asdfasfasfs
\begin{Exercises}
    \exercise\ What is 2+2?
    \exercise\hard How many angels can fit on the head of a pin?
    \exercise\veryhard Prove the four-color theorem
\end{Exercises}

\section{A  hard section\hard}
asfdAFASFAF

\section{Very hard section\veryhard}
asfdAFASFAF


\end{document}
% ---------------------------------------------------------------- 

输出

在此处输入图片描述

另一个解决方案是定义两个新命令

\newcommand{\exhard}{\hspace*{-\labelsep}\hard}
\newcommand{\exveryhard}{\hspace*{-\labelsep}\veryhard}

并使用它们代替\hard\veryhard之后\exercise

梅威瑟:

\documentclass[12pt]{book}

\usepackage{xspace}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Define new list type for exercises
% from: http://tex.stackexchange.com/questions/196199/exercise-list-using-enumitem-how-control-indentation-and-labeling-of-sublists
% by: Daniel Wunderlich
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\usepackage{enumitem}      % this should be loaded in book.Rnw
%
\newlist{Exercises}{enumerate}{2}
% set list style parameters
\setlist[Exercises]{%
  label=\textbf{Exercise \thechapter.\arabic*},  % Label: Exercise Chapter.exercise
  ref=\thechapter.\arabic*, % References: Chapter.exercise (important!)
  align=left,               % Left align labels
  labelindent=0pt,          % No space betw. margin of list and label
  leftmargin=0pt,           % No space betw. margin of list and following lines
  itemindent=!,             % Indention of item computed automatically
  itemsep=3pt,
}

\newcommand{\exercise}{%
  \item\label{lab:\arabic{chapter}.\arabic{Exercisesi}}%      % Append label to item
  \setlist[enumerate, 1]{label=(\alph*),itemsep=0pt}          % Label for subexercises, but only within an exercise
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Symbols for hard or difficult sections and problems
\newcommand{\hard}{$^\star$\xspace}
\newcommand{\veryhard}{$^{\star\star}$\xspace}

\newcommand{\exhard}{\hspace*{-\labelsep}\hard}
\newcommand{\exveryhard}{\hspace*{-\labelsep}\veryhard}


\begin{document}

\chapter{First chapter}
\section{First section}
asdfasfasfs
\begin{Exercises}
    \exercise What is 2+2?
    \exercise\exhard How many angels can fit on the head of a pin?
    \exercise\exveryhard Prove the four-color theorem
\end{Exercises}

\section{A  hard section\hard}
asfdAFASFAF

\section{Very hard section\veryhard}
asfdAFASFAF


\end{document}
% ---------------------------------------------------------------- 

输出:

在此处输入图片描述


编辑

如果你想改善练习的外观,你可以定义以下命令

\newcommand{\simpleexercise}{\exercise\ \hphantom{\veryhard}}
\newcommand{\hardexercise}{\exercise\hard\hphantom{\hard}}
\newcommand{\veryhardexercise}{\exercise\veryhard\hphantom{\ }}

并使用它们代替,\exercise如以下示例所示

\documentclass[12pt]{book}

\usepackage{xspace}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Define new list type for exercises
% from: http://tex.stackexchange.com/questions/196199/exercise-list-using-enumitem-how-control-indentation-and-labeling-of-sublists
% by: Daniel Wunderlich
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\usepackage{enumitem}      % this should be loaded in book.Rnw
%
\newlist{Exercises}{enumerate}{2}
% set list style parameters
\setlist[Exercises]{%
  label=\textbf{Exercise \thechapter.\arabic*},  % Label: Exercise Chapter.exercise
  ref=\thechapter.\arabic*, % References: Chapter.exercise (important!)
  align=left,               % Left align labels
  labelindent=0pt,          % No space betw. margin of list and label
  leftmargin=0pt,           % No space betw. margin of list and following lines
  itemindent=!,             % Indention of item computed automatically
  itemsep=3pt,
  labelsep=0pt,
}

\newcommand{\exercise}{%
  \item\label{lab:\arabic{chapter}.\arabic{Exercisesi}}%      % Append label to item
  \setlist[enumerate, 1]{label=(\alph*),itemsep=0pt}          % Label for subexercises, but only within an exercise
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Symbols for hard or difficult sections and problems
\newcommand{\hard}{$^\star$\xspace}
\newcommand{\veryhard}{$^{\star\star}$\xspace}

\newcommand{\simpleexercise}{\exercise\ \hphantom{\veryhard}}
\newcommand{\hardexercise}{\exercise\hard\hphantom{\hard}}
\newcommand{\veryhardexercise}{\exercise\veryhard\hphantom{\ }}


\begin{document}

\chapter{First chapter}
\section{First section}
asdfasfasfs
\begin{Exercises}
    \simpleexercise What is 2+2?
    \hardexercise How many angels can fit on the head of a pin?
    \veryhardexercise Prove the four-color theorem
\end{Exercises}

\section{A  hard section\hard}
asfdAFASFAF

\section{Very hard section\veryhard}
asfdAFASFAF


\end{document}
% ---------------------------------------------------------------- 

输出:

在此处输入图片描述

相关内容