5

I want to define my paragraphs and subsubsections to always be inside of a transparent box with a certain color.

I know that there's a transparency-package but this doesn't work with the PDF-view only with PS-view (i don't really understand why, but it seems that I can't use it for what i want to do), I also found a solution with the package tikz but i don't really understand how it works. Here is an Example where someone uses tikz and gets a transparent box with transparent text (I only want a transparent box - no transparent text).

Until now I only used Latex for writing protocols in a&a Style, so I don't know much about redefining commands and things like that. I am using the document class article with texmaker. I am producing a PDF-workbook for students so I need the solution to be compatible with PDF.

I'm trying to make a minimal example of what I did so far:

\documentclass[a4paper, 12pt, DIV10]{article}

\usepackage[ngerman]{babel}
\usepackage{xcolor}
\usepackage[explicit]{titlesec}
\usepackage{lipsum}

\titleformat{\subsubsection}
  {\normalfont\Large\bfseries}
  {}
  {0em}
  {\colorbox{orange}{\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\textcolor{blue}{\thesection\quad#1}}}} 



\setcounter{secnumdepth}{4}

\titleformat{\paragraph}
  {\normalfont\Large\bfseries}
  {}
  {0em}
  {\colorbox{red}{\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\textcolor{green}{\thesection\quad#1}}}} 


  \begin{document}

  \section{Kapitel}
\lipsum[1]


\subsubsection*{Erklärung}
\lipsum[2]

\paragraph*{Übungen}
\lipsum[3]

  \end{document}

I hope you can help me, if I forgot to mention anything let me know, and I'll figure it out.

3
  • Welcome to the site. Your example doesn't give any clue as to why transparency is required, since there is nothing behind the colored boxes. So what are the real requirements? – Steven B. Segletes Jul 28 '16 at 15:46
  • 1
    maybe transparency wasn't the right word - when I defined my color i got a nice light blue but the color was too 'intense' . I like the shade of this color (don't want to change it) but i want to make it faded (just like in the example - the box in the middle is olive-green and the box above is olive-green as well, but more 'transparent/faded'. However I don't want my text to also become transparent/faded ) – Karfloffel Jul 28 '16 at 15:59
  • You don't need all the complications brought about by transparancy to achieve your goal. Complex colors can be built. For example red!40 defines a color that is 40% red, the remainder white, whereas red!40!black is 40% red, 60% black. The complexity knows no bound: red!40!black!60!green, etc. – Steven B. Segletes Jul 28 '16 at 16:54
4

Two variants:

\documentclass[a4paper, 12pt, DIV10]{article}

\usepackage[ngerman]{babel}
\usepackage{xcolor}
\usepackage[explicit]{titlesec}
\usepackage{lipsum}
\usepackage{tikz}
\titleformat{\subsubsection}
  {\normalfont\Large\bfseries}
  {}
  {0em}
  {\pgfsetfillopacity{0.5}\colorbox{orange}{\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\textcolor{blue}{\thesection\quad#1}}}\pgfsetfillopacity{1}}



\setcounter{secnumdepth}{4}

\titleformat{\paragraph}
  {\normalfont\Large\bfseries}
  {}
  {0em}
  {\tikz\node[opacity=0.5,fill=red,inner sep=\fboxsep,anchor=base]{\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\textcolor{green}{\thesection\quad#1}}};}


  \begin{document}

  \section{Kapitel}
\lipsum[1]


\subsubsection*{Erklärung}
\lipsum[2]

\paragraph*{Übungen}
\lipsum[3]

  \end{document}

enter image description here

If you want a different opacity for the text:

\documentclass[a4paper, 12pt, DIV10]{article}

\usepackage[ngerman]{babel}
\usepackage{xcolor}
\usepackage[explicit]{titlesec}
\usepackage{lipsum}
\usepackage{tikz}
\titleformat{\subsubsection}
  {\normalfont\Large\bfseries}
  {}
  {0em}
  {\pgfsetfillopacity{0.5}\colorbox{orange}{\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\textcolor{blue}{\pgfsetfillopacity{1}\thesection\quad#1}}}}



\setcounter{secnumdepth}{4}

\titleformat{\paragraph}
  {\normalfont\Large\bfseries}
  {}
  {0em}
  {\tikz\node[opacity=0.5,text opacity=1,fill=red,inner sep=\fboxsep,anchor=base]{\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\textcolor{green}{\thesection\quad#1}}};}


\begin{document}

\section{Kapitel}
\lipsum[1]


\subsubsection*{Erklärung}
\lipsum[2]

\paragraph*{Übungen}
\lipsum[3]

  \end{document}

enter image description here

Side remark: In case the DIV10 in your example means that in your real document you aren't using article but a KOMA class, be aware that they don't like titlesec much.

2
  • Thank you for your help, thats exactly what i wanted for the boxes, however the text is also faded, which is exactly what I wanted to avoid. Is there possibly a way to use \pgfsetfillopacity (or just define the opacity) in \definecolor so that it only affects the box? – Karfloffel Jul 28 '16 at 16:17
  • @Karfloffel: I edited the answer. – Ulrike Fischer Jul 28 '16 at 16:33

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.