TeX - LaTeX Asked by Yehor on February 14, 2021
I’m looking for a way to modify or make an alternative to the warning/alarm messages in text alike this one from awesombox
package:
What I need to do is:
In the documentation I found that the image can be replaced with symbols from a certain font, but no mentioning of using externally loaded image and no explanation of how to make a doubled line.
How it should be implemented?
An awesomebox
is implemented as a tabular (i.e., a table) with the icon in one column, the text in another, and the colored vertical bar in between. You can do the same without the package with a tabularx
environment. The double lines can be shown using ||
as column separator.
The column with the text can use X
as column separator, which means 'a paragraph column with the remaining available width'.
To get the image top-aligned with the text the align=t
option for includegraphics
provided by the package graphbox
can be used. Additionally, to improve vertical spacing around the warning box I added 12pt on the top and bottom.
MWE:
documentclass{article}
usepackage{graphbox}
usepackage{tabularx}
newcommand{customwarning}[1]{%
vskip12pt
begin{tabularx}{textwidth}{p{2.5cm}||X}
centeringincludegraphics[align=t,width=2cm]{warningsign} & #1
end{tabularx}
vskip12pt
}
begin{document}
customwarning{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam aliquet libero quis lectus elementum fermentum. Fusce aliquet augue sapien, non efficitur mi ornare sed. Morbi at dictum felis. Pellentesque tortor lacus, semper et neque vitae, egestas commodo nisl.}
Other text
customwarning{This is a frog}
end{document}
Result:
Edit: with an optional argument to specify the image (either just the filename or the image with a path specification).
documentclass{article}
usepackage{graphbox}
usepackage{tabularx}
% the default filename is 'warningsign', change this if you have a different default name
newcommand{customwarning}[2][warningsign]{%
vskip12pt
begin{tabularx}{textwidth}{p{2.5cm}||X}
centeringincludegraphics[align=t,width=2cm]{#1} & #2
end{tabularx}
vskip12pt
}
begin{document}
% image given as argument
customwarning[warningsign]{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam aliquet libero quis lectus elementum fermentum. Fusce aliquet augue sapien, non efficitur mi ornare sed. Morbi at dictum felis. Pellentesque tortor lacus, semper et neque vitae, egestas commodo nisl.}
Other text
% without argument, default value is used for the image name/location
customwarning{This is a frog}
end{document}
Correct answer by Marijn on February 14, 2021
With the help of tcolorbox
:
documentclass{article}
usepackage[most]{tcolorbox}
usepackage[export]{adjustbox}
usepackage{lipsum}
newtcolorbox{myColorBox}{%
sidebyside,
sidebyside align=top,
lower separated=true,
lefthand width=2.5cm,
arc=0pt,
left=0pt,right=0pt,top=0pt,bottom=0pt,
colback=white,
enhanced,
segmentation style={draw=black,double distance=3pt,solid},
boxrule=0pt,
sidebyside gap=20pt,
width=textwidth,
}
newenvironment{MyBox}[1][example-image] % replace "example-image" with file name of default image
{begin{myColorBox} includegraphics[width=2.5cm,valign=t]{#1}tcblower}
{end{myColorBox}}
begin{document}
begin{MyBox} % omit optional argument for defautlt image
lipsum[5]
end{MyBox}
begin{MyBox}[example-image-a] % use optional argument to insert non-default image
lipsum[5]
end{MyBox}
lipsum[5]
end{document}
Answered by leandriis on February 14, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP