我正在尝试复制编程书籍中的一个常见模式,作者习惯于为简短、强调的文本部分创建一些设计,这些设计在使用的图标/图像上有所不同,例如
或者:
最后:
上述每种风格都来自使用 3、4 个版本的书籍(仅更改了具有不同含义的图标)
到目前为止,我只能够创建一个非常基本的 mdframe 示例以供课堂使用scrbook
:
\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}
我正在寻找一种方法来创建一些newmdenv
我想要的东西:
\begin{infoaside}
% ...
\end{infoaside}
\begin{warningaside}
%...
\end{warningaside}
它们每个都会在 mdframe 的左上角有一个图像(或者理想情况下是一个 FontAwesome 图标),并且主体(文本、列表等)会相应地填充,如所提供的示例所示。
任何能够指导我完成此过程的帮助都将不胜感激。
谢谢
答案1
我认为用 可以很容易地得到你想要的东西tcolorbox
。
从此开始Ignasi 的回答,我创建了两种盒子,borderbox
和boxwithoutborder
,它们有一个强制参数,你可以用它来放置你喜欢的图像/符号。这两种盒子都可以透过书页打破。
\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}
答案2
希望我理解你的问题。你想得到这样的东西吗?
\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}
要获得另一个符号,您可以考虑此链接中用户@Schrödinger's cat 的最佳答案:车速表作为符号放入 awesomebox