3

I want to draw a tikz node that has as its baseline the baseline of the text around and have a drop shadow. My code however causes the drop shadow to be misplaced.

\documentclass[]{standalone}
\usepackage{tikz}
\usetikzlibrary{shadows.blur}

\newcommand{\propbox}[1]{
    \hspace{-.125cm}\tikz[baseline=(A.base)]{\node[
      fill = red,
      blur shadow={shadow blur steps=5}] (A) {#1};}
}


\begin{document}
This is \propbox{some} sample text.
\end{document}

enter image description here

Compare this to the correct shadow, where the baseline for the node is not specified:

enter image description here

How can I fix the shadow?

6

Here is a temporary hack that you can use:

enter image description here

Note

  • Are per Torbjørn T's suggestion, you can eliminate the \hspace{-.125cm} hack by inserting a % follwoing the open paren as that eliminates the suprious space that was being inserted.

Code:

\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shadows.blur}


\newcommand{\propbox}[1]{%
    %\hspace{-.125cm} <-- Hack fixed by % above
    \tikz[baseline=(A.base)]{
        \node[outer sep=1pt,
          fill = red,
          blur shadow={
              shadow blur steps=5,
              baseline=(A.south),% <--- ADDED
          },
        ] (A) {#1};%
    }% <--- NOTE. Without this you will have additional space following the `\propbox'
}


\begin{document}
This is \propbox{some} sample text.
\end{document}
1

using tcolorbox

\documentclass[]{article}
\usepackage{tikz}
\usetikzlibrary{shadows.blur}

\usepackage{tcolorbox}
\tcbuselibrary{skins}

\newcommand{\propbox}[1]{
  \hspace{-.125cm}\tikz[baseline=(A.base)]{\node[
    fill = red,
    blur shadow={shadow blur steps=5}] (A) {#1};}
}

\begin{document}

This is \propbox{some} sample text.

This is \tcbox[enhanced, size=fbox, drop fuzzy shadow=black, 
nobeforeafter, boxsep=2pt, coltext=white, frame hidden, on line,
colback=red!75,]{some} sample text

\end{document}

enter image description here

  • Thanks, but is there a solution with tikz? This was just a minimal working example and I have a lot of tikz stuff in my actual code. For example I have these boxes shaded in my actual code and I just spent 30 min trying to figure out how I can do that with this tcolobox thing. – lo tolmencre Nov 17 '17 at 18:26

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.