3

I am searching a way to highlight in a particular way a text in latex. I know already the existence of the command \hl; however, it does not provide the result that I want.

Actually, I would like to add a vertical tick grey line on the left of a given paragraph. As I cannot go beyond the authorized margin of the document, the line should move somehow the text in the paragraph slightly on the right.

Do you know how to do that?

1

An alternative answer, making boxes breakable accross pages

\documentclass{article}
\usepackage{tcolorbox,tikz, lipsum}
\tcbuselibrary{skins}
\tcbuselibrary{breakable}
\begin{document}
\begin{tcolorbox}[breakable, enhanced,colback=yellow!10!white,boxrule=0pt,frame hidden,
borderline west={1mm}{-2mm}{black}]
\lipsum[1-7]
\end{tcolorbox}
\end{document}

enter image description here

1

Please find mdframed based reply. Advantage of this is if paragraph is longer, then page breaks are smooth. This is given as a reply to some question in this forum.

\documentclass{article}

\usepackage{mdframed} % Add easy frames to paragraphs
\usepackage{lipsum} % For dummy text
\usepackage{xcolor}
\usepackage{xparse} % Add support for \NewDocumentEnvironment
\definecolor{graylight}{cmyk}{.30,0,0,.67} % define color using xcolor syntax

\newmdenv[ % Define mdframe settings and store as leftrule
  linecolor=graylight,
  linewidth=4pt,
  topline=false,
  bottomline=false,
  rightline=false,
  skipabove=\topsep,
  skipbelow=\topsep
]{leftrule}

\NewDocumentEnvironment{parahigh}{O{{}}} % Define example environment
{\begin{leftrule}\noindent\textcolor{graylight}{#1}\par}
{\end{leftrule}}

\begin{document}



\begin{parahigh}
\lipsum
\end{parahigh}
\end{document}
1

This approach cannot break across a page boundary.

\documentclass{article}
\usepackage{xcolor}
\usepackage[nopar]{lipsum}
\newcommand\specpar[1]{%
  \edef\svparindent{\the\parindent}%
  \setbox0=\hbox{\parbox[t]{\dimexpr\textwidth-6pt}{\strut\hspace{\svparindent}#1\strut}}%
  \par%
  \noindent\textcolor{gray}{\rule[-\dp0]{2pt}{\dimexpr\dp0+\ht0}}\kern4pt\copy0%
  \par%
}
\begin{document}

\lipsum[1]

\specpar{\lipsum[2]}

\lipsum[3]
\end{document}

enter image description here

1

You also can use the leftbarenvironment from the framed package. It can break across pages. Here is an example, with a customised environment:

\documentclass[11pt]{article}
\usepackage{framed} %
\usepackage[table, svgnames]{xcolor}
\usepackage{lipsum} %
\usepackage[defaultlines=2,all]{nowidow}

\colorlet{barcolour}{Lavender!80!Gainsboro}
\renewenvironment{leftbar}{%
\def\FrameCommand{{\color{barcolour}\vrule width 4pt} \hspace{0.25em}}%{\dimexpr\parindent-3pt-\fontdimen2\font \relax}
\MakeFramed {\advance\hsize-\width \FrameRestore}\noindent\hspace{-\fontdimen2\font}}%
{\endMakeFramed}

\begin{document}

\lipsum[1-2]
\begin{leftbar}
  \lipsum[3-5]
\end{leftbar}

\end{document} 

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.