删除符号或图像的一部分

删除符号或图像的一部分

整理并提出已回答的次要问题

我正在尝试将特定区域中的人员数量组合成视觉辅助工具,因此我设想使用类似的东西。在其他地方回答时使用marvosym带有的包\Gentsroom作为符号。

男人形象

是否有一种简单的方法来遮蔽图像的一半,例如,如果我使用每个图形来表示四个人,并且我想用半个图形来表示 2?

链接到以下先前的问题 关于 tikz 中人体形状的问题

注:标题很糟糕,但这就是我所能想到的。请随意编辑。

答案1

(此答案来自原始问题

如果我正确理解了这个问题,下面的代码可能有助于设计出一个合适的解决方案:

\documentclass{article}
\usepackage{tikz}
\usepackage[margin=2mm]{geometry}
\usepackage{marvosym}
\usepackage{graphicx}
\def\rowofmen#1{%
\begin{tikzpicture}[x=2mm,y=3mm]
\path[clip] (0,0) rectangle (#1,1.1);
\pgfmathparse{ceil(#1)}
\foreach \i in {0,...,\pgfmathresult} {
\node[inner sep=0pt, above right] at (\i, 0) 
   {\resizebox{2mm}{3mm}{\Gentsroom}};
  }
\end{tikzpicture}
}

\begin{document}
\noindent%
\textcolor{gray}{\rowofmen{5}}\\
\textcolor{black!.3!blue}{\rowofmen{3.5}}\\
\rlap{\textcolor{red}{\rowofmen{5}}}%
\rlap{\textcolor{blue}{\rowofmen{3.7}}}%
\rlap{\textcolor{green}{\rowofmen{2.5}}}%
\\    
\end{document}

\rowofmen{x}产生一排X男人,允许分数值X(诀窍是再画一个人,然后剪裁结果图)。叠加几行不同的颜色和长度(如示例所示\rlap),您可以模拟半阴影的人。这是输出:

输出

x=2mm,y=3mm请注意,每个人的尺寸都调整为 2mm x 3mm。您可以通过更改tikzpicture和 的参数来改变这一点\resizebox。其余部分可以保持不变。

答案2

我会用 Ti 剪辑符号 Z,而不是在其一部分上绘制一个白色矩形。这样,这在彩色物体前面也能起作用,而不会出现白色框。

我还使用了环境,这样在操作之前就能知道pgfinterruptboundingbox的尺寸(这与 类似)。 因为是测量的,所以它代替了和类似的字体大小宏。\Gentsroom\clip\?lap
\Gentsroom\Large

\LeftGent[<>]{<opt>}\RightGent[<>]{<opt>}

是否给出了一个(空)可选参数<>,则部分符号将占据原始符号的整个宽度。

\setlength{\fboxsep}{0pt}\setlength{\fboxrule}{.2pt}
\fbox{\LeftGent{}\Gentsroom\RightGent{}} \fbox{\LeftGent[]{}\Gentsroom\RightGent[]{}}

在此处输入图片描述

强制参数<opt>(可以为空,但必须给出)赋予 s \node

\RightGent{opacity=.2}\LeftGent{}\RightGent{}\LeftGent{yshift=-.5ex,red}

在此处输入图片描述

\partGent[<>]{<opt>}{<perc>}\trapGent[<>]{<opt>}{<perc>}

除了和之外<><opt>这些宏还接受一个加法参数<perc>,因此可以使用符号的任意部分。当然,只有0.0和之间的值才有意义。1.0

\rowOfGents[<>]{<opt>}{<count>}worOfGents[<>]{<opt>}{<count>}

这些宏构建了一整排的男人。<><opt>像往常一样行动。<count>给出应该排版的符号的(浮动)数量。

\rowOfGents{green}{2.5}\worOfGents{blue}{0.5}\rowOfGents{blue}{0.7}\worOfGents{red}{1.3}\par
\Large\rowOfGents{green}{2.5}\worOfGents{blue}{.5}\rowOfGents{blue}{.7}\worOfGents{red}{1.3}

在此处输入图片描述

代码

\documentclass{article}
\usepackage{marvosym}
\usepackage{tikz}
\usetikzlibrary{calc}
\newif\ifclipme
\newcommand*{\LeftGent}[2][\clipmetrue]{\reflectbox{\RightGent[#1]{#2}}}
\newcommand*{\RightGent}[2][\clipmetrue]{\partGent[#1]{#2}{.5}}
\newcommand*{\trapGent}[3][\clipmetrue]{\reflectbox{\partGent[#1]{#2}{#3}}}
\newcommand*{\partGent}[3][\clipmetrue]{%
  \sbox0{\Gentsroom}%
  \tikz[baseline]
  { #1
    \ifclipme\begin{pgfinterruptboundingbox}\fi
    \node [anchor=south, inner sep=0pt, outer sep=0pt, text width=\wd0, text height=\ht0, text depth=\dp0, #2] (A) {}; %
    \ifclipme\end{pgfinterruptboundingbox}\fi
    \clip (A.south west) rectangle ($(A.north west)!#3!(A.north east)$);
    \node [anchor=base, inner sep=0pt, outer sep=0pt, #2] {\Gentsroom};
  }%
}
\newcommand*{\rowOfGents}[3][\clipmetrue]{%
  \pgfmathtruncatemacro\fullGents{int(#3)}%
  \pgfmathsetmacro\partGents{mod(#3,1)}%
  \ifnum\fullGents>0\relax\foreach \i in {1,...,\fullGents}{\partGent[#1]{#2}{1}}\fi%
  \ifdim\partGents pt>0.0pt\relax\partGent[#1]{#2}{\partGents}\fi%
}
\newcommand*{\worOfGents}[3][\clipmetrue]{\reflectbox{\rowOfGents[#1]{#2}{#3}}}
\begin{document}
\setlength{\fboxsep}{0pt}\setlength{\fboxrule}{.2pt}
\fbox{\LeftGent{}\Gentsroom\RightGent{}} \fbox{\LeftGent[]{}\Gentsroom\RightGent[]{}}
\RightGent{opacity=.2}\LeftGent{}\RightGent{}\LeftGent{yshift=-.5ex,red}% That's gonna hurt!

\rowOfGents{green}{2.5}\worOfGents{blue}{0.5}\rowOfGents{blue}{0.7}\worOfGents{red}{1.3}\par
\Large\rowOfGents{green}{2.5}\worOfGents{blue}{0.5}\rowOfGents{blue}{0.7}\worOfGents{red}{1.3}
\end{document}

答案3

您可以使用tikz在要剪切的区域上绘制一个白色矩形。以下是两个宏\RightHalf,具体\LeftHalf取决于要剪切哪一侧:

在此处输入图片描述

代码:

\documentclass[10pt]{article}
\usepackage{marvosym}
\usepackage{tikz}

\newcommand{\RightHalf}{%
\begin{tikzpicture}%
  \node [inner sep=0pt, outer sep=0pt] (A) {\Gentsroom};
  \draw [draw=none,fill=white] (A.south west) rectangle (A.north);
\end{tikzpicture}%
}

\newcommand{\LeftHalf}{%
\begin{tikzpicture}%
  \node [inner sep=0pt, outer sep=0pt] (A) {\Gentsroom};
  \draw [draw=none,fill=white] (A.south east) rectangle (A.north);
\end{tikzpicture}%
}

\begin{document} 

\RightHalf \Gentsroom \Gentsroom \LeftHalf 
\end{document} 

答案4

还有一个不使用 TikZ 的解决方案:

\documentclass[10pt]{article}
\usepackage{marvosym}
\newcommand{\RightHalf}{\clipbox{2.195pt 0 0 0}{\Gentsroom}}
\newcommand{\LeftHalf}{\clipbox{0 0 2.195pt 0}{\Gentsroom}}
\usepackage{trimclip}
\begin{document}

% ======== to compute the magic constant 2.195pt above: ========
\setbox0=\hbox{\Gentsroom}
\the\wd0  % 4.39pt, divide it by 2 to get 2.195pt

\RightHalf \Gentsroom \Gentsroom \LeftHalf 
\end{document} 

或者,您也可以选择在“运行时”计算魔法常量,而不是对其进行硬编码:

\documentclass[10pt]{article}
\usepackage{marvosym}
\usepackage{trimclip}
\begin{document}


\begingroup
\setbox0=\hbox{\Gentsroom}
\dimen0=\wd0  % after this, dimen0 = width of a \Gentsroom symbol
\divide\dimen0 by2  % after this, dimen0 = half the width of a \Gentsroom symbol
\def\tmp #1{
    \endgroup
    \newcommand\RightHalf{\clipbox{#1 0 0 0}{\Gentsroom}}  % substitute its value into occurrences of #1 here
    \newcommand\LeftHalf{\clipbox{0 0 #1 0}{\Gentsroom}}
}
\expandafter\tmp\expandafter{\the\dimen0}


\RightHalf \Gentsroom \Gentsroom \LeftHalf 
\end{document} 

参考:https://tex.stackexchange.com/a/201623/250119

相关内容