我想绘制一个 tikz 节点,其基线是周围文本的基线和有阴影。但我的代码导致阴影位置错误。
\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}
将其与正确的阴影进行比较,其中未指定节点的基线:
我该如何修复阴影?
答案1
以下是您可以使用的一个临时解决方法:
笔记
- 根据 Torbjørn T 的建议,您可以
\hspace{-.125cm}
通过在%
左括号后插入一个来消除这种黑客攻击,因为这样可以消除插入的过多空格。
代码:
\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}
答案2
使用 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}