我正在用 LaTeX 写一篇文章。
请建议我如何在 LaTeX 中创建如下所示的高亮框:
答案1
您可以使用bclogo
和/或mdframed
和或tcolorbox
包。
主要区别在于使用mdframed
或制作的框tcolorbox
可能允许分页。
一个小例子;第一个盒子是使用 制作的bclogo
;第二个盒子使用mdframed
;第三个(与第二个类似)和第四个盒子是使用 制作的tcolorbox
:
\documentclass{book}
\usepackage{xcolor}
\usepackage[tikz]{bclogo}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{lipsum}
\usepackage[many]{tcolorbox}
\definecolor{bgblue}{RGB}{245,243,253}
\definecolor{ttblue}{RGB}{91,194,224}
\mdfdefinestyle{mystyle}{%
rightline=true,
innerleftmargin=10,
innerrightmargin=10,
outerlinewidth=3pt,
topline=false,
rightline=true,
bottomline=false,
skipabove=\topsep,
skipbelow=\topsep
}
\newtcolorbox{myboxi}[1][]{
breakable,
title=#1,
colback=white,
colbacktitle=white,
coltitle=black,
fonttitle=\bfseries,
bottomrule=0pt,
toprule=0pt,
leftrule=3pt,
rightrule=3pt,
titlerule=0pt,
arc=0pt,
outer arc=0pt,
colframe=black,
}
\newtcolorbox{myboxii}[1][]{
breakable,
freelance,
title=#1,
colback=white,
colbacktitle=white,
coltitle=black,
fonttitle=\bfseries,
bottomrule=0pt,
boxrule=0pt,
colframe=white,
overlay unbroken and first={
\draw[red!75!black,line width=3pt]
([xshift=5pt]frame.north west) --
(frame.north west) --
(frame.south west);
\draw[red!75!black,line width=3pt]
([xshift=-5pt]frame.north east) --
(frame.north east) --
(frame.south east);
},
overlay unbroken app={
\draw[red!75!black,line width=3pt,line cap=rect]
(frame.south west) --
([xshift=5pt]frame.south west);
\draw[red!75!black,line width=3pt,line cap=rect]
(frame.south east) --
([xshift=-5pt]frame.south east);
},
overlay middle and last={
\draw[red!75!black,line width=3pt]
(frame.north west) --
(frame.south west);
\draw[red!75!black,line width=3pt]
(frame.north east) --
(frame.south east);
},
overlay last app={
\draw[red!75!black,line width=3pt,line cap=rect]
(frame.south west) --
([xshift=5pt]frame.south west);
\draw[red!75!black,line width=3pt,line cap=rect]
(frame.south east) --
([xshift=-5pt]frame.south east);
},
}
\begin{document}
\renewcommand\bcStyleTitre[1]{\large\textcolor{ttblue}{#1}}
\begin{bclogo}[
couleur=bgblue,
arrondi=0,
logo=\bcbombe,
barre=none,
noborder=true]{Commom Programming Error}
\itshape\lipsum[4]
\end{bclogo}
\begin{mdframed}[style=mystyle,frametitle=Web addresses in text]
\lipsum[4]
\end{mdframed}
\begin{myboxi}[Web addresses in text]
\lipsum[4]
\end{myboxi}
\begin{myboxii}[Web addresses in text]
\lipsum[4]
\end{myboxii}
\end{document}
这些软件包为您提供了许多定制可能性并且文档包含大量示例。
对于第二个框架,使用以下另一个选项TikZ
:
\documentclass{book}
\usepackage{environ}
\usepackage{xcolor}
\usepackage[tikz]{bclogo}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{lipsum}
\NewEnviron{myremark}[1]
{\par\medskip\noindent
\begin{tikzpicture}
\node[inner sep=0pt] (box) {\parbox[t]{.99\textwidth}{%
\begin{minipage}{.3\textwidth}
\centering\tikz[scale=5]\node[scale=3,rotate=30]{\bclampe};
\end{minipage}%
\begin{minipage}{.65\textwidth}
\textbf{#1}\par\smallskip
\BODY
\end{minipage}\hfill}%
};
\draw[red!75!black,line width=3pt]
( $ (box.north east) + (-5pt,3pt) $ ) -- ( $ (box.north east) + (0,3pt) $ ) -- ( $ (box.south east) + (0,-3pt) $ ) -- + (-5pt,0);
\draw[red!75!black,line width=3pt]
( $ (box.north west) + (5pt,3pt) $ ) -- ( $ (box.north west) + (0,3pt) $ ) -- ( $ (box.south west) + (0,-3pt) $ ) -- + (5pt,0);
\end{tikzpicture}\par\medskip%
}
\begin{document}
\lipsum[4]
\begin{myremark}{Web addresses in texts}
\lipsum[4]
\end{myremark}
\lipsum[4]
\end{document}
答案2
这里有一个例子mdframed
,其中的符号取自包,dingbat
你可以使用每张图片来代替符号。
\documentclass{report}
\usepackage[framemethod=tikz]{mdframed}
\usetikzlibrary{calc}
\usepackage{kantlipsum}
\usepackage{dingbat}%\eye and \leftpointright
\newcounter{error}[chapter]
\renewcommand*\theerror{\thechapter.\arabic{error}}
\tikzset{
errorsymbol/.style={%
rectangle,draw=blue,
,scale=2,overlay}}
\tikzset{
lampsymbol/.style={%
,scale=2,overlay}}
\newmdenv[hidealllines=true,backgroundcolor=blue!5,%
frametitle={\stepcounter{error}Comman~Programming~Error~\theerror},
frametitlefont=\color{blue!80!black}\bfseries,
skipabove=\topsep,skipbelow=\topsep,nobreak,
leftmargin=.3cm,rightmargin=.3cm, innerleftmargin=2cm,
singleextra={\path let \p1=(P), \p2=(O) in ($(\x2,0)+0.5*(2,\y1)$) node[errorsymbol] {\eye};},%
]{error}
\newmdenv[nobreak,middlelinewidth=.8pt,
frametitlefont=\bfseries,
leftmargin=.3cm,rightmargin=.3cm, innerleftmargin=2cm,
skipabove=\topsep,skipbelow=\topsep,
singleextra={\path let \p1=(P), \p2=(O) in ($(\x2,0)+0.5*(2,\y1)$) node[ lampsymbol] {\leftpointright};
\draw[line width=.8pt,white,] ($(O|-P)+(.2cm,0)$) -- ($(P)-(.2cm,0)$);
\draw[line width=.8pt,white,] ($(O)+(.2cm,0)$) -- ($(P|-O)-(.2cm,0)$);
},%
]{lamp}
\begin{document}
\begin{error}
Use only uppercase letters in the names of enumeration constants to make these
constants stand out in a program and to indicate that enumeration constants
are variables.
\end{error}
\begin{lamp}[frametitle={Web addresses in texts}]
Use only uppercase letters in the names of enumeration constants to make these
constants stand out in a program and to indicate that enumeration constants
are variables.
\end{lamp}
\end{document}
答案3
awesomebox
提供了一些默认的“高亮框”,但可以扩展:
\documentclass{article}
\usepackage{awesomebox}
\usepackage[nopar]{lipsum}
\begin{document}
\lipsum[1]
\notebox{\lipsum[2]}
\tipbox{\lipsum[3]}
\warningbox{\lipsum[4]}
\cautionbox{\lipsum[5]}
\importantbox{\lipsum[6]}
\lipsum[7]
\end{document}
答案4
\usepackage[most]{tcolorbox}
%textmarker style from colorbox doc
\tcbset{textmarker/.style={%
enhanced,
parbox=false,boxrule=0mm,boxsep=0mm,arc=0mm,
outer arc=0mm,left=6mm,right=3mm,top=7pt,bottom=7pt,
toptitle=1mm,bottomtitle=1mm,oversize}}
% define new colorboxes
\newtcolorbox{hintBox}{textmarker,
borderline west={6pt}{0pt}{yellow},
colback=yellow!10!white}
\newtcolorbox{importantBox}{textmarker,
borderline west={6pt}{0pt}{red},
colback=red!10!white}
\newtcolorbox{noteBox}{textmarker,
borderline west={6pt}{0pt}{green},
colback=green!10!white}
% define commands for easy access
\newcommand{\note}[1]{\begin{noteBox} \textbf{Note:} #1 \end{noteBox}}
\newcommand{\warning}[1]{\begin{hintBox} \textbf{Warning:} #1 \end{hintBox}}
\newcommand{\important}[1]{\begin{importantBox} \textbf{Important:} #1 \end{importantBox}}
\begin{document}
% draw some highlight boxes
\note{Certainly elsewhere my do allowance at. The address farther six hearted hundred towards husband. Strangers ye to he sometimes propriety in. She right plate seven has. Bed who perceive judgment did marianne.}
\warning{Doubtful two bed way pleasure confined followed. Shew up ye away no eyes life or were this.}
\important{Travelling alteration impression six all uncommonly. Chamber hearing inhabit joy highest private ask him our believe. Up nature valley do warmly. Entered of cordial do on no hearted.}
\end{document}
。
结果如下: