我需要在 Latex 中划掉一个单词,如下所示:
但我需要将十字旋转 45 度。每当我添加 rotate=45 时,我也会旋转单词,这不是我想要的:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}
\usepackage{rotating}
\newcommand*{\mycancel}[2][draw]{%
\begin{tikzpicture}
\node[cross out,rotate=45,inner sep=0pt,outer sep=0pt, #1]{#2};
\end{tikzpicture}
}
\begin{document}
\mycancel{A}
\end{document}
旋转没有帮助:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}
\usepackage{rotating}
\newcommand*{\mycancel}[2][draw]{%
\begin{tikzpicture}
\node[cross out,rotate=45,inner sep=0pt,outer sep=0pt, #1]{#2};
\end{tikzpicture}
}
\begin{document}
\mycancel{\begin{rotate}{315}A\end{rotate}}
\end{document}
答案1
这里移除tikzpicture
环境并添加另一个节点用于实际交叉。然后添加\tikz[baseline=(one.base)]{...}
以设置适当的基线。
输出
代码
\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes}
\newcommand{\mycancel}[3][]{%
\tikz[baseline=(one.base)]{
\node[draw=none, inner sep=0,outer sep=0, #1] (one) at (0,0) {#2};
\node[draw,cross out, inner sep=0, outer sep=0, rotate=#3, #1, minimum size=.2cm] at (one) {\phantom{#2}};
}
}
\begin{document}
Hello, there this is an \mycancel{A}{0}
\mycancel{\huge A}{15}
\mycancel{\Large A}{262}
\mycancel{\footnotesize A}{150}
\end{document}
答案2
一个简单的\draw
命令可能是一种更简单的方法:
\documentclass{article}
\usepackage{tikz}
\newcommand*{\mycancel}[2][]{%
\begin{tikzpicture}[inner sep=0pt, baseline=(X.base)]
\node (X) {#2};
\draw[#1] (X.west) -- (X.east) (X.south) -- (X.north);
\end{tikzpicture}%
}
\begin{document}
\mycancel{A}\qquad\mycancel[red, thick]{hello world}\qquad\mycancel{g}
\end{document}