1

I am needing to write a risk assessment report, the headings within the report are risks that have been discovered, next to each of the headings/risks I'm needing to use a key or coloured boxes to highlight the severity of the risk in question, how am I able to do this in LaTeX, a brief mock up example from word would look like the attached picture.

I'm using the hyperref package to create the menu structure in the PDF menu.

Example

I tried the following from the comments below.

{\section{Heading} \color{red} \rule{0.2in}{0.2in}}

Whilst this gives me a box, I'd of liked to of had the border if possible, and also for it to be on the same line as the heading, with the above code the box is on the next line down with the body text for that heading.

The following code gives errors, but otherwise does what I am after albeit no border around the box..

\section{Heading \color{red} \rule{0.2in}{0.2in}}
  • 2
    Please show us what you have tried so far! – Kurt Feb 4 at 22:37
  • 2
    Well, is the box always of the same width or does the width of the box indicate the risk? The box is pretty easy with TikZ, but how is the heading done? – user31729 Feb 4 at 22:40
  • 3
    If you need just a rectangle without border, a simple \rule{}{} with \textcolor{}{} should work. – Sigur Feb 4 at 22:43
1

mwe

\documentclass{article}
\usepackage{xcolor}
\begin{document}

\def\risk#1{\fcolorbox{black}{red}{\color{red}\makebox[#1em]{x}}}
\setcounter{section}{0}\section*{Risk assessments:}
\section{Tipple \risk{1}}
\section{Drive a car \risk{3}}
\section{Tipple and drive a car \risk{10}}

\vspace{1cm}

\def\risk#1{{\fboxsep0pt\protect\fbox{\color{red}\rule{#1em}{1ex}}}}
\setcounter{section}{0}\section*{Risk assessments:}
\section{Tipple \risk{1}}
\section{Drive a car \risk{3}}
\section{Tipple and drive a car \risk{10}}

\end{document}

Note that used just as sowed in the above MWE, the rule will be printed also in the table of contents and page headings as is really part of the section title, but you can use the optional argument of \section to supply a short title without the rule or anything else, as the risk level as a number instas of a bar. If you are too lazy to type the section title twice, there is one way to simplify:

\documentclass{article}
\def\risk#1:#2 {\section[#1 (risk level: #2)]{#1 \fboxsep0pt\protect\fbox{\color{red}\rule{#2em}{1ex}}}}
\usepackage{xcolor}
\usepackage[linkcolor=blue,colorlinks]{hyperref}
\begin{document}
\tableofcontents
\risk Tipple:1
\risk Drive a car:3
\risk Tipple and drive a car:10
\end{document}

mwe2

  • Just watch for entries in the ToC, or in the PDF ToC. – Werner Feb 5 at 0:42
  • @Werner I do not see any other problem that in case of a ToC you must use the optional argument of section, e.g., \section[Tipple]{Tipple \risk{1}}. – Fran Feb 5 at 0:53
  • @Fran Would it be possible to somehow have the box outside of the \section but also on the same line as the header in the pdf? also the boxes are to be used as a key so will all be the same size the only difference being the colour in the box. – AeroMaxx Feb 5 at 5:59
  • \section{} break the line (paragraph) and add a vertical space, no anything after will be displaced to the start of the nomal paragraph, unless you redefine this command. – Fran Feb 5 at 22:58

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.