用于在视觉上区分文本的环境

用于在视觉上区分文本的环境

我有一个文档,其中包含来自不同声音的交替段落。由于段落块看起来太相似,我需要某种方式使不同部分具有不同的外观。

我已经尝试过改为斜体或粗体等选项,但我不想影响可读性。我想知道是否有其他环境可以将它放置在某些段落或其他视觉元素周围,以便让读者轻松知道哪个部分是哪个?

答案1

有很多方法可以做到这一点:

  1. 您可以简单地使用不同颜色的文本,或者也许以下组合会产生您喜欢的效果。

  2. mdframed下面是使用该包突出显示不同部分的示例:

    在此处输入图片描述

  3. 您可以使用adjustwidth来自的环境包裹changepage从视觉上区分这两个段落:

    在此处输入图片描述

  4. 你可以使用包裹changebar

    在此处输入图片描述

  5. 如果你的段落不是太大,你可以使用以下解决方案标记文本部分而不影响间距制作段落的开始和结束:

    在此处输入图片描述

  6. 如果你想要不需要使用单独段落的解决方案,这里有一个与 相当的版本mdframed,它使用了来自 的解决方案LaTeX 中的酷炫文本突出显示提供手动生成的突出显示: 在此处输入图片描述


代码:mdframed

\documentclass[border=5pt]{standalone}
\usepackage{xcolor}
\usepackage{mdframed}
\usepackage{lipsum}

\newmdenv[
    backgroundcolor=yellow!10,
    rightline=false,
    leftline=false,
    topline=false,
    bottomline=false,
    innertopmargin=1pt,
    innerbottommargin=1pt,
    innerleftmargin=0,
    innerrightmargin=0,
]{VoiceA}

\newmdenv[
    backgroundcolor=gray!10,
    rightline=false,
    leftline=false,
    topline=false,
    bottomline=false,
    innertopmargin=1pt,
    innerbottommargin=1pt,
    innerleftmargin=0,
    innerrightmargin=0,
]{VoiceB}

\begin{document}
\begin{VoiceA}
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
    Phasellus ut elit ipsum. 
    In massa metus, suscipit vel semper in, sodales sed risus. 
    Aliquam gravida ultricies sollicitudin. 
\end{VoiceA}
\begin{VoiceB}
    Vivamus et sem velit. 
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam erat volutpat. 
    Sed rhoncus neque a orci vulputate ut elementum dui ornare.  
\end{VoiceB}
\begin{VoiceA}
    Nulla id magna metus. Integer lacus dolor, tempus ac sodales 
    eu, blandit nec ligula. 
    Etiam quis arcu ac nisi lobortis ultricies quis in dolor. 
    Quisque lobortis magna arcu.
\end{VoiceA}
\end{document}

代码:adjustwidth

\documentclass[border=5pt]{standalone}
\usepackage{lipsum}
\usepackage{changepage}

\newenvironment{VoiceA}{%
    \begin{adjustwidth}{0pt}{1.0cm}%
}{%
    \end{adjustwidth}%
}

\newenvironment{VoiceB}{%
    \begin{adjustwidth}{1.0cm}{0pt}%
}{%
    \end{adjustwidth}%
}
\begin{document}
\begin{VoiceA}
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
    Phasellus ut elit ipsum. 
    In massa metus, suscipit vel semper in, sodales sed risus. 
    Aliquam gravida ultricies sollicitudin. 
\end{VoiceA}
\begin{VoiceB}
    Vivamus et sem velit. 
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam erat volutpat. 
    Sed rhoncus neque a orci vulputate ut elementum dui ornare.  
\end{VoiceB}
\begin{VoiceA}
    Nulla id magna metus. Integer lacus dolor, tempus ac sodales 
    eu, blandit nec ligula. 
    Etiam quis arcu ac nisi lobortis ultricies quis in dolor. 
    Quisque lobortis magna arcu.
\end{VoiceA}
\end{document}

代码:changebar

\documentclass{article}
\usepackage{lipsum}
\usepackage[xcolor,outerbars]{changebar}

\setlength\changebarsep{5pt}
\newenvironment{VoiceA}{%
    \cbcolor{red}%
    \par%
    \cbstart%
}{%
%
    \cbend%
}

\newenvironment{VoiceB}{%
    \cbcolor{white}% gets cluttered if both have changebars
    \par%
    \cbstart%
}{%
    \cbend%
}
\begin{document}
\begin{VoiceA}
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
    Phasellus ut elit ipsum. 
    In massa metus, suscipit vel semper in, sodales sed risus. 
    Aliquam gravida ultricies sollicitudin. 
\end{VoiceA}
\begin{VoiceB}
    Vivamus et sem velit. 
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam erat volutpat. 
    Sed rhoncus neque a orci vulputate ut elementum dui ornare.  
\end{VoiceB}
\begin{VoiceA}
    Nulla id magna metus. Integer lacus dolor, tempus ac sodales 
    eu, blandit nec ligula. 
    Etiam quis arcu ac nisi lobortis ultricies quis in dolor. 
    Quisque lobortis magna arcu.
\end{VoiceA}
\end{document}

代码:段落标记:

\documentclass[border=5pt]{standalone}
\usepackage{environ}
\usepackage{tikz}
\usepackage{mathabx}

% https://tex.stackexchange.com/questions/24174/mark-portions-of-text-without-affecting-spacing

\DeclareRobustCommand{\MarkStart}[1]{{%
  \setbox0=\llap{\raisebox{5pt}{\color{#1}$\Rsh$\kern-6pt}}%
  \ht0=0pt \dp0=0pt \leavevmode\box0
}}
\DeclareRobustCommand{\MarkEnd}[1]{{%
  \setbox0=\rlap{\raisebox{5pt}{\color{#1}\kern-6pt$\Lsh$}}%
  \ht0=0pt \dp0=0pt \leavevmode\box0
}}
\newcommand*{\Mark}[1]{\MarkStart#1\MarkEnd}

\NewEnviron{VoiceA}{\par\MarkStart{red}\BODY\MarkEnd{red}}
\NewEnviron{VoiceB}{\par\MarkStart{blue}\BODY\MarkEnd{blue}}

\begin{document}
\begin{VoiceA}
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
    Phasellus ut elit ipsum. 
    In massa metus, suscipit vel semper in, sodales sed risus. 
    Aliquam gravida ultricies sollicitudin. 
\end{VoiceA}
\begin{VoiceB}
    Vivamus et sem velit. 
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam erat volutpat. 
    Sed rhoncus neque a orci vulputate ut elementum dui ornare.  
\end{VoiceB}
\begin{VoiceA}
    Nulla id magna metus. Integer lacus dolor, tempus ac sodales 
    eu, blandit nec ligula. 
    Etiam quis arcu ac nisi lobortis ultricies quis in dolor. 
    Quisque lobortis magna arcu.
\end{VoiceA}
\end{document}

代码:炫酷高亮:

\documentclass[border=5pt]{standalone}
\usepackage{soul}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.pathmorphing}

% https://tex.stackexchange.com/questions/5959/cool-text-highlighting-in-latex

\makeatletter
\newcommand{\defhighlighter}[3][]{%
  \tikzset{every highlighter/.style={color=#2, fill opacity=#3, #1}}%
}

\defhighlighter{yellow}{.3}

\newcommand{\highlight@DoHighlight}{
  \fill [ decoration = {random steps, amplitude=1pt, segment length=55pt}
        , outer sep = -15pt, inner sep = 0pt, decorate
        , every highlighter, this highlighter ]
        ($(begin highlight)+(0,8pt)$) rectangle ($(end highlight)+(0,-3pt)$) ;
}

\newcommand{\highlight@BeginHighlight}{
  \coordinate (begin highlight) at (0,0) ;
}

\newcommand{\highlight@EndHighlight}{
  \coordinate (end highlight) at (0,0) ;
}

\newdimen\highlight@previous
\newdimen\highlight@current

\DeclareRobustCommand*\highlight[1][]{%
  \tikzset{this highlighter/.style={#1}}%
  \SOUL@setup
  %
  \def\SOUL@preamble{%
    \begin{tikzpicture}[overlay, remember picture]
      \highlight@BeginHighlight
      \highlight@EndHighlight
    \end{tikzpicture}%
  }%
  %
  \def\SOUL@postamble{%
    \begin{tikzpicture}[overlay, remember picture]
      \highlight@EndHighlight
      \highlight@DoHighlight
    \end{tikzpicture}%
  }%
  %
  \def\SOUL@everyhyphen{%
    \discretionary{%
      \SOUL@setkern\SOUL@hyphkern
      \SOUL@sethyphenchar
      \tikz[overlay, remember picture] \highlight@EndHighlight ;%
    }{%
    }{%
      \SOUL@setkern\SOUL@charkern
    }%
  }%
  %
  \def\SOUL@everyexhyphen##1{%
    \SOUL@setkern\SOUL@hyphkern
    \hbox{##1}%
    \discretionary{%
      \tikz[overlay, remember picture] \highlight@EndHighlight ;%
    }{%
    }{%
      \SOUL@setkern\SOUL@charkern
    }%
  }%
  %
  \def\SOUL@everysyllable{%
    \begin{tikzpicture}[overlay, remember picture]
      \path let \p0 = (begin highlight), \p1 = (0,0) in \pgfextra
        \global\highlight@previous=\y0
        \global\highlight@current =\y1
      \endpgfextra (0,0) ;
      \ifdim\highlight@current < \highlight@previous
        \highlight@DoHighlight
        \highlight@BeginHighlight
      \fi
    \end{tikzpicture}%
    \the\SOUL@syllable
    \tikz[overlay, remember picture] \highlight@EndHighlight ;%
  }%
  \SOUL@
}
\makeatother

\begin{document}
\highlight[yellow]{
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
    Phasellus ut elit ipsum. 
    In massa metus, suscipit vel semper in, sodales sed risus. 
    Aliquam gravida ultricies sollicitudin. 
}
\highlight[gray]{
    Vivamus et sem velit. 
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam erat volutpat. 
    Sed rhoncus neque a orci vulputate ut elementum dui ornare.  
}
\highlight[yellow]{
    Nulla id magna metus. Integer lacus dolor, tempus ac sodales 
    eu, blandit nec ligula. 
    Etiam quis arcu ac nisi lobortis ultricies quis in dolor. 
    Quisque lobortis magna arcu.
}
\end{document}

相关内容