rstudio / rmarkdown-cookbook

R Markdown Cookbook. A range of tips and tricks to make better use of R Markdown.
https://bookdown.org/yihui/rmarkdown-cookbook/
578 stars 224 forks source link

9.6.3 infobox code #393

Open jdambroise opened 1 year ago

jdambroise commented 1 year ago

In 9.6.3 it appears there is an error in the following code. The image appears outside of the blackbox not inside. Although I'm playing around to find a solution myself, I wonder if someone can provide a correction quicker than I can figure it.

 \newenvironment{infobox}[1]
   {
   \begin{itemize}
   \renewcommand{\labelitemi}{
     \raisebox{-.7\height}[0pt][0pt]{
       {\setkeys{Gin}{width=3em,keepaspectratio}
         \includegraphics{images/#1}}
     }
   }
   \setlength{\fboxsep}{1em}
   \begin{blackbox}
   \item
   }
   {
   \end{blackbox}
   \end{itemize}
   }
jdambroise commented 1 year ago

Got it. Here is the solution.

 \newenvironment{infobox}[1]
   {
   \begin{blackbox}
   \begin{itemize}
   \renewcommand{\labelitemi}{
     \raisebox{-.7\height}[0pt][0pt]{
       {\setkeys{Gin}{width=3em,keepaspectratio}
         \includegraphics{images/#1}}
     }
   }
   \setlength{\fboxsep}{1em}
   \item
   }
   {
   \end{itemize}
   \end{blackbox}
   }
cderv commented 1 year ago

This is how it looks like in current PDF book I believe image

I believe this is expected for us that the icon is not inside the blackbox... @yihui I don't have the printed version with me, but is there any change ?

You could indeed put inside the blackbox, and glad you found the solution BTW.

dambroisej commented 1 year ago

oh that looks nice too, thanks ! i will do another comparison and make a choice

yihui commented 1 year ago

I believe this is expected for us that the icon is not inside the blackbox... @yihui I don't have the printed version with me, but is there any change ?

@cderv That's what we have in the printed version. The icons are not inside the boxes.

@jdambroise Thanks for sharing the solution!