29

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.

  • 2
    I usually use {\fontencoding{U}\fontfamily{futs}\selectfont\char 66\relax} for that symbol. – Nicola Talbot Feb 10 '14 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). – Charles Staats Feb 10 '14 at 17:53
  • 1
    You also have \usepackage{bclogo} and \bcattention. – Gonzalo Medina Feb 11 '14 at 1:51
  • this command is incompatible with \usepackage[french]{babel} – user36123 Sep 7 '15 at 13:28
31

The fourier package provides \danger:

\documentclass{article}

\usepackage{fourier}

\begin{document}

\danger

\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 66\relax}

\end{document}

which is essentially what \danger 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 the letter B in the \char 66 slot.

  • 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. – Radon Rosborough May 10 '17 at 3:08
  • Thanks, @RadonRosborough. I was initially getting a "B". [at]NicolaTalbot could you add that to the answer as well? – Aalok Jun 8 '17 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? – Matthias Braun Sep 25 at 8:49
22

You could have a better look at the The Comprehensive LATEX Symbol List.

The symbol is called \danger and it is provided by the fourier package.

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

16

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}
13

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

  • Perhaps it's my imagination, but the exclamation point in the small version looks slightly off-center. – Charles Staats Feb 10 '14 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. – Steven B. Segletes Feb 10 '14 at 20:05
  • A question about the stackrel package: why does it render the \danger symbol from the fourier package as a letter B? – Charles Staats Feb 11 '14 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. – Steven B. Segletes Feb 11 '14 at 2:33
  • Your guess seems to have been entirely correct. Thanks! – Charles Staats Feb 11 '14 at 4:29
9

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?”)

  • With the most recent version of the STIX fonts, the call should be \setmainfont[Ligatures=TeX]{STIX} – egreg Feb 10 '14 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. – Charles Staats Feb 10 '14 at 18:48
  • 2
    @CharlesStaats: You can use ASCII characters: ^^^^26a0, see The ^^ notation in various engines – Heiko Oberdiek Feb 10 '14 at 18:54
5

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.