46

I am interested in including a triangle with an exclamation point (unicode #9888: ⚠) in a tex document. I've looked in the usual places (detexify, etc.) and not found this symbol. The document should be compilable with pdflatex and the source should have ASCII encoding. I already have a tikz version that I like reasonably well, given by

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\newcommand{\warningsign}{\tikz[baseline=-.75ex] \node[shape=regular polygon, regular polygon sides=3, inner sep=0pt, draw, thick] {\textbf{!}};}
\begin{document}
\warningsign Warning
\end{document}

so I am also requiring that the answer be an actual character, or at least not done using graphics.

4
  • 3
    I usually use {\fontencoding{U}\fontfamily{futs}\selectfont\char 66\relax} for that symbol. Feb 10, 2014 at 17:38
  • @Nicola Talbot: Works like a charm! Please add that as an answer so that I can upvote it (and accept it unless someone comes along with a deeper explanation). Feb 10, 2014 at 17:53
  • 1
    You also have \usepackage{bclogo} and \bcattention. Feb 11, 2014 at 1:51
  • this command is incompatible with \usepackage[french]{babel}
    – user36123
    Sep 7, 2015 at 13:28

7 Answers 7

43

The fourier package provides \warning:

\documentclass{article}

\usepackage{fourier}

\begin{document}

\warning

\end{document}

I sometimes find that some of the fourier commands conflict with other packages I use, so if I only want this symbol I do:

\documentclass{article}

\begin{document}

{\fontencoding{U}\fontfamily{futs}\selectfont\char 49\relax}

\end{document}

which is essentially what \warning does. This requires the futs font family which is provided with the fourier package, so the package must still be installed even though it's not actually being loaded.

If the futs font isn't available, the transcript will show the message:

LaTeX Font Warning: Font shape `U/futs/m/n' undefined
(Font)              using `U/cmr/m/n' instead on input line 5.

This means that the cmr font is being used instead, which has something else in the \char 49 slot.

4
  • 1
    In the second example, note that you need to have the fourier package installed in your TeX Live distribution even though it is not explicitly loaded. Otherwise, you will just get a "B" instead of a warning triangle. May 10, 2017 at 3:08
  • Thanks, @RadonRosborough. I was initially getting a "B". [at]NicolaTalbot could you add that to the answer as well?
    – axolotl
    Jun 8, 2017 at 10:13
  • I get this error in a Beamer document on Arch Linux: "mktexpk: don't know how to create bitmap font for futr8r. mktexpk: perhaps futr8r is missing from the map file." Is there another package I have to install? Sep 25, 2019 at 8:49
  • 2
    Be aware that the command is now called \warning. Also, character number has changed to 49. So for option two use {\fontencoding{U}\fontfamily{futs}\selectfont\char 49\relax}.
    – Isotope
    Mar 25, 2022 at 15:58
32

A \warning symbol (previously \danger) is provided by the fourier package (see The Comprehensive LATEX Symbol List, table 475, page 177).

If you don't have the need for the complete fourier package, but you want to use that symbol, you can extract it and use in your document:

\newcommand*{\TakeFourierOrnament}[1]{{%
\fontencoding{U}\fontfamily{futs}\selectfont\char#1}}
\newcommand*{\danger}{\TakeFourierOrnament{66}}

MWE

\documentclass{article}

\newcommand*{\TakeFourierOrnament}[1]{{%
\fontencoding{U}\fontfamily{futs}\selectfont\char#1}}
\newcommand*{\danger}{\TakeFourierOrnament{66}}

\begin{document}

\danger

\end{document}

Output

enter image description here

2
  • 4
    In my installation of TeX Live 2022, this MWE produces a different output. It looks like the position of the symbol in the alphabet was changed at some point, nowadays it is 49 rather than 66... Jul 20, 2022 at 10:43
  • I needed to use \TakeFourierOrnament{`1} (not 66). Whatever...
    – cis
    Mar 6 at 16:51
29

A simple build assigned to the unicode symbol, so you can use or \Warning:

mWE

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage{newunicodechar}

\newcommand\Warning{%
 \makebox[1.4em][c]{%
 \makebox[0pt][c]{\raisebox{.1em}{\small!}}%
 \makebox[0pt][c]{\color{red}\Large$\bigtriangleup$}}}%

\newunicodechar{⚠}{\Warning}

\begin{document}

    Do⚠not⚠put your finger

    on the power plug.

\end{document}
2
  • Great! It's been a while since this answer, but I needed it today and it exactly suited me. Thanks a ton. May 24 at 15:09
  • Same thing but bigger: \newcommand\Warning{% \makebox[1.4em][c]{% \makebox[0pt][c]{\raisebox{.2em}{!}}% \makebox[1pt][c]{\color{red}\LARGE$\bigtriangleup$}}}% Sep 8 at 12:05
23

Here, I choose to build my own by overlaying a black, tiny ! atop a red $\triangle$, and then scaling the result to a desired [optional] size

\documentclass{article}
\usepackage{stackengine}
\usepackage{scalerel}
\usepackage{xcolor}
\newcommand\dangersign[1][2ex]{%
  \renewcommand\stacktype{L}%
  \scaleto{\stackon[1.3pt]{\color{red}$\triangle$}{\tiny !}}{#1}%
}
\begin{document}
This is a danger sign 5ex tall: \dangersign[5ex]\par
Here is the default (2ex) size: \dangersign
\end{document}

Zoom of result, to clarify my response to Charles' comment.

enter image description here

If one prefers a bolder !, just make it \bfseries:

\documentclass{article}
\usepackage{stackengine}
\usepackage{scalerel}
\usepackage{xcolor}
\newcommand\dangersign[1][2ex]{%
  \renewcommand\stacktype{L}%
  \scaleto{\stackon[1.3pt]{\color{red}$\triangle$}{\tiny\bfseries !}}{#1}%
}
\begin{document}
This is a danger sign 5ex tall: \dangersign[5ex]\par
Here is the default (2ex) size: \dangersign
\end{document}

enter image description here

5
  • Perhaps it's my imagination, but the exclamation point in the small version looks slightly off-center. Feb 10, 2014 at 20:03
  • @CharlesStaats Sometimes, when glyphs are overlaid, inexact rendering will make them appear off center. Zooming in reveals a better approximation, and the printed result is accurate. Zooming the small symbol to 6400% reveals aligned glyphs. Feb 10, 2014 at 20:05
  • A question about the stackrel package: why does it render the \danger symbol from the fourier package as a letter B? Feb 11, 2014 at 2:26
  • @CharlesStaats Do you mean scalerel package? I would note that scalerel macros process their argument in math mode, by default, and one must actually delimit them with $...$ to process in text mode. So my guess is that the symbol is being processed in the wrong mode. Feb 11, 2014 at 2:33
  • Your guess seems to have been entirely correct. Thanks! Feb 11, 2014 at 4:29
13

When you use XeLaTeX or LuaLaTeX you can simply use the character as is:

\documentclass{article}
\usepackage{fontspec}
\setmainfont[Ligatures=TeX]{STIXGeneral}
\newcommand\warningsign{⚠}
\begin{document}
    \warningsign Warning
\end{document}

Of course the font must contain it. (STIX does.)

It looks like this:

Warning sign

Notice that it is more common to give unicode code points in hexadecimal, here U+26A0.

If you don’t want to have unusual characters in your source code, you can specify the warning sign by its code point:

\newcommand\warningsign{\symbol{"26A0}}

(Found at “How do I enter an arbitrary Unicode code point into my document?”)

3
  • 1
    With the most recent version of the STIX fonts, the call should be \setmainfont[Ligatures=TeX]{STIX}
    – egreg
    Feb 10, 2014 at 18:36
  • I appreciate the information, but prefer that my source code contain no characters that do not show up on my (American) keyboard. Feb 10, 2014 at 18:48
  • 2
    @CharlesStaats: You can use ASCII characters: ^^^^26a0, see The ^^ notation in various engines Feb 10, 2014 at 18:54
12

The package fontawesome provides the commands \faWarning (equiv., \faExclamationTriangle for the warning icon, which looks like this:

enter image description here

A minimal example would be:

\documentclass{article}
\usepackage{fontawesome}

\begin{document}

\faWarning\, Warning: This product contains peanuts, %
which might not be very suitable for certain individuals.

\end{document}

The fontawesome package might be new, but it provides a wide range of high-quality web icons, and that makes it pretty relevant tool in terms of modern typesetting and design.

0

enter image description here

\documentclass{article}
\usepackage{tikz}
\begin{document}
\newcommand\danger[1][]{%
\begin{tikzpicture}[baseline=-0.5ex, inner xsep=0pt,#1]
\node[]{$\triangle$};
\node[yshift=0.125ex, scale=0.45]{!};
\end{tikzpicture}\space}

A danger-sing \danger is shown here.

\huge A danger-sing \danger[red] is shown here.
\end{document}
3
  • 1
    sing? did you mean "sign"?
    – Thruston
    Mar 6 at 16:09
  • 1
    Also the OP explicitly asked for a solution using a character, and "not done using graphics"
    – Thruston
    Mar 6 at 16:11
  • Yes, sign - I misspelled :(
    – cis
    Mar 6 at 16:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .