小边距注释并排放置以避免重叠

小边距注释并排放置以避免重叠

我定义了这个函数\corr,它用红色或蓝色标记一段文本或公式并添加边注。问题是每行有多个更正,因为这样会重叠。如果每行有多个更正,我想将它们并排显示。这是我的代码:

\documentclass[]{article}
\usepackage{xstring}
\usepackage{marginnote}
\usepackage{tikz}

\newcounter{correctioncounter}

\newcommand{\corr}[2]{%
    \refstepcounter{correctioncounter}%
    \IfEqCase{#1}{
        {a}{{\color{red}#2\marginnote{%
                    \begin{tikzpicture}%
                    \draw node[draw,inner sep=2pt] {\tiny \arabic{correctioncounter}};
                    \end{tikzpicture} }}}% correction
        {b}{{\color{blue}#2\marginnote{%
                    \begin{tikzpicture}%
                    \draw node[draw,inner sep=2pt] {\tiny \arabic{correctioncounter}};
                    \end{tikzpicture} }}}% suggestion
        {c}{#2}% Turn correction into plain text
        {d}{} % Erase
    }[\PackageError{correction command}{Undefined for corr: #1}{}]%
}
\begin{document}

Random text with a \corr{a}{correction} in one line.

Having more than one \corr{a}{correction} in \corr{a}{one} line causes them to overlap. Some more random text to show that the annotations are really in the \corr{b}{margin}. 

\end{document}

输出结果如下: 在此处输入图片描述

答案1

您可以为\corr哪个控件添加另一个参数\marginparsep并重置其默认值。如果marginnote不是当前行中的最后一个,则必须像这样添加add到命令中corr\corr[add]{a}{text}

\documentclass[]{article}
\usepackage{xstring}
\usepackage{marginnote}
\usepackage{tikz}

\newcounter{correctioncounter}

\newcommand{\corr}[3][]{%
    \refstepcounter{correctioncounter}%
    \IfEqCase{#2}{
        {a}{{\color{red}#3\marginnote{%
                    \begin{tikzpicture}%
                    \draw node[draw,inner sep=2pt] {\tiny \arabic{correctioncounter}};
                    \end{tikzpicture}}}}% correction
        {b}{{\color{blue}#3\marginnote{%
                    \begin{tikzpicture}%
                    \draw node[draw,inner sep=2pt] {\tiny \arabic{correctioncounter}};
                    \end{tikzpicture} }}}% suggestion
        {c}{#3}% Turn correction into plain text
        {d}{} % Erase
    }[\PackageError{correction command}{Undefined for corr: #2}{}]
    \IfEqCase{#1}{{add}{\advance \marginparsep by 3mm}{}{\marginparsep=11pt}}
}
\begin{document}

Random text with a \corr{a}{correction}\ in one line.

Having more than one \corr[add]{a}{correction}\ in \corr[add]{a}{one}\ line causes them to  \corr{b}{overlap}. Some more random text to show that the annotations are really in the \corr{b}{margin}. 

\end{document}

在此处输入图片描述

相关内容