2

I'm trying to replicate a common pattern in programming books, where authors use to create few designs for brief, emphasized text portions that differ in the icon/image used, e.g.

Packt Publishing style

or also:

enter image description here

and finally:

enter image description here

Each of the above styles comes from books where 3, 4 versions are used (changing only the icon, that carries a different meaning)

So far I've only been able to create a very basic mdframe example to be used in a scrbook class:

\documentclass[
    letterpaper,
    12pt,
    oneside
]{scrbook}

\usepackage{lipsum}
\usepackage{pstricks}
\usepackage[framemethod=PSTricks]{mdframed}

\begin{document}

\mdfdefinestyle{roundframe}{
  leftmargin=1cm,
  rightmargin=1cm, 
  innerleftmargin=2cm,
  innerrightmargin=2cm,
  roundcorner=10pt
 }

\newmdenv[style=roundframe]{framedaside}

\lipsum[1]  

\begin{framedaside}
In any right triangle, the area of the square whose side is the hypotenuse is equal to the sum of the areas of the squares whose sides are the two legs.
\end{framedaside}

\lipsum[1]  

\end{document}

enter image description here

I'm after a way to create few newmdenv where I would:

\begin{infoaside}
% ...
\end{infoaside}

\begin{warningaside}
%...
\end{warningaside}

Each of them would have an image (or ideally a FontAwesome icon) in the top-left part of the mdframe, and the body – either text, listings, etc. – padded accordingly, as in the examples provided.

Any help in guiding me through this would be greatly appreciated.

Thank you

unDavide
  • 265
  • 2
    Check this answer please https://tex.stackexchange.com/a/501680/120578 (and all the other answers in this topic) – koleygr Oct 02 '19 at 14:28
  • 1
    Thanks! I did search a lot on this subject, but I've always been looking for "asides" and mdframed, it has never occurred to me that they might be called "highlight boxes". awesomebox might do the trick in the short term, then I may want to borrow other solutions provided in the thread you've linked. Thanks again. – unDavide Oct 02 '19 at 15:56
  • Welcome @user1625148 ... Happy TeXing – koleygr Oct 02 '19 at 22:06
  • 1
    Look also tthe bclogo package https://tex.stackexchange.com/a/163249/11604 and – Fran Oct 02 '19 at 22:54

2 Answers2

1

I hope I understand your question. Would you like to get something like this?

enter image description here

\documentclass[a4paper,12pt]{article}
\usepackage[margin=2cm]{geometry}
\usepackage{awesomebox}
\usepackage{fontawesome5}

\usepackage{lipsum}
\begin{document}
 \setlength{\parindent}{0pt}
\lipsum[1][1-2]

\awesomebox{0pt}{\faCogs}{black}{\lipsum[1][1-3]
\begin{itemize}
\itemsep-.5em 
    \item This is the first paragraph;
    \item This is the second paragraph
\end{itemize}
\lipsum[2][3-5]}

\lipsum[1][1-3]
\end{document}

To have another symbol you can consider the best answer of the user @Schrödinger's cat at this link: Speedometer as a symbol into awesomebox

Sebastiano
  • 54,118
  • Thanks! awesomebox looks great, alas it doesn't span on multiple pages (I've requested it as a feat. to the author's github repo). I am currently trying to modify an example I've found on the mdframed package but I'd need guidance: what's the proper way, should I open a new thread or just go with the "answer your question" button? Thanks! – unDavide Oct 03 '19 at 19:48
1

I think it's easy to get what you want with tcolorbox.

Starting from this answer by Ignasi, I've created two kinds of boxes, borderbox and boxwithoutborder, which have a mandatory argument you can use to put the image/symbol you like. These boxes are both breakable through the pages.

\documentclass[
    letterpaper,
    12pt,
    oneside
    ]{scrbook}

\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{fontawesome}
\usepackage[most]{tcolorbox}
\tcbuselibrary{breakable}
%From: https://tex.stackexchange.com/questions/319355/tcolorbox-breakable-option-not-working
\newtcolorbox{borderbox}[2][]{
    enhanced jigsaw,
    breakable,
    notitle,
    sharpish corners,
    before skip=\baselineskip,
    opacityback=0,
    opacityframe=0,
    leftupper=1.5cm,
    overlay unbroken={
        \node[anchor=north west] at ([xshift=2mm,yshift=-2mm]frame.north west) {#2};
        \draw[very thick] ([xshift=10pt]frame.north west) -| (frame.south west) -- ++(10pt,0);
        \draw[very thick] ([xshift=-10pt]frame.north east) -| (frame.south east) -- ++(-10pt,0);
        },
    overlay first={
        \node[anchor=north west] at ([xshift=2mm,yshift=-2mm]frame.north west) {#2};
        \draw[very thick] ([xshift=10pt]frame.north west) -| (frame.south west);
        \draw[very thick] ([xshift=-10pt]frame.north east) -| (frame.south east);
        },
    overlay middle={
        \draw[very thick] (frame.north west) -- (frame.south west);
        \draw[very thick] (frame.north east) -- (frame.south east);
        },
    overlay last={
        \draw[very thick] (frame.north west) -- (frame.south west) -- ++(10pt,0);
        \draw[very thick] (frame.north east) -- (frame.south east) -- ++(-10pt,0);
        },
    #1
}
\newtcolorbox{boxwithoutborder}[2][]{
    enhanced jigsaw,
    breakable,
    notitle,
    sharpish corners,
    before skip=\baselineskip,
    opacityback=0,
    opacityframe=0,
    leftupper=1.5cm,
    overlay unbroken={
        \node[anchor=north west] at ([xshift=2mm,yshift=-2mm]frame.north west) {#2};
        },
    overlay first={
        \node[anchor=north west] at ([xshift=2mm,yshift=-2mm]frame.north west) {#2}; },
    #1
}
\begin{document}

    \lipsum[2]
    \begin{borderbox}{\resizebox{1cm}{!}{\faCogs}}
        \lipsum[2]
    \end{borderbox}
    \lipsum[2]
    \begin{borderbox}{\includegraphics[width=1cm]{example-image-a}}
        \lipsum
    \end{borderbox}
    \lipsum[2]
    \begin{boxwithoutborder}{\includegraphics[width=1cm]{example-image-a}}
        \lipsum[2]
    \end{boxwithoutborder}
    \lipsum[2]
    \begin{boxwithoutborder}{\resizebox{1cm}{!}{\faCogs}}
        \lipsum
    \end{boxwithoutborder}
\end{document}

enter image description here enter image description here enter image description here enter image description here enter image description here

CarLaTeX
  • 62,716