Tikz:使用乳胶长度作为路径的长度(同上标记)

Tikz:使用乳胶长度作为路径的长度(同上标记)

我想画一条重复线,即一条水平线,中间有两个小标记。

我的第一次尝试是\dittoLatex使用带有字符和规则的盒子,但坦率地说很丑陋。

我的第二次尝试\dittotikzA看起来好多了,但并没有根据参数自动计算它的宽度。

我的第三次尝试是\dittotikzB使用与 相同的方法来计算宽度\dittoLatex,但不起作用。我怀疑问题出在单位不匹配,但我不知道如何修复它。

梅威瑟:

\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{xparse}

\makeatletter

\usepackage{tikz}
\usetikzlibrary{math}

\newcommand\dittotikzA[1][3em]{%
    \def\x{#1/4}%
    %\show\x%
    \def\y{#1*.01}%
    \begin{tikzpicture}[x=1ex,y=1ex,baseline=-.5ex,cap=round]
        \draw (0,0) sin (1*\x,\y) cos (2*\x,0) sin (3*\x,-\y) cos (4*\x,0);
        \draw[xshift=-.2ex, bend right=20] (2*\x-.5,-.5) edge (2*\x+.5,.5);
        \draw[xshift=.2ex, bend right=20] (2*\x-.5,-.5) edge (2*\x+.5,.5);
    \end{tikzpicture}%
}


\newlength{\ditto@width}
\NewDocumentCommand\dittotikzB{ s O{1em} m }{%
    % #1 = starred means horizontal line along entire width, unstarred means no line (only ditto marks)
    % #2 = minimum width
    % #3 = string to use for calculating width
    \settowidth{\ditto@width}{#3}%
    %\show\ditto@width%
    \edef\w{\ifdim#2<\ditto@width\the\ditto@width\else#2\fi}
    %\show\w%
    \begin{tikzpicture}[x=1ex,y=1ex,baseline=-.5ex,cap=round]
        \tikzmath{
            \xfactor = \w / 4 * 1pt/1ex;
            \yfactor = .175;
        };
        %\show\xfactor;
        %\show\yfactor;
        \IfBooleanT{#1}{% starred
            \draw (0,0) sin (1\xfactor, \yfactor) cos (2\xfactor, 0) sin (3\xfactor, -\yfactor) cos (4\xfactor, 0);
        };
        \draw[xshift=-.2ex, bend right=20] (2\xfactor - .5, -.5) edge (2\xfactor + .5, .5);
        \draw[xshift=.2ex, bend right=20] (2\xfactor - .5, -.5) edge (2\xfactor + .5, .5);
    \end{tikzpicture}%
}


\usepackage{xhfill}
\newcommand\ditto@symbol{%
    ||%
}
\NewDocumentCommand\dittoLatex{ s O{1em} m }{%
    % #1 = starred means horizontal line along entire width, unstarred means no line (only ditto marks)
    % #2 = minimum width
    % #3 = string to use for calculating width
    \settowidth{\ditto@width}{#3}%
    \makebox[{\ifdim#2<\ditto@width\ditto@width\else#2\fi}]{%
        \IfBooleanTF{#1}{% starred
            \xrfill[.5ex]{.4pt}%
            \ditto@symbol%
            \xrfill[.5ex]{.4pt}%
        }{%
            \ditto@symbol%
        }%
    }%
}

\makeatother

\begin{document}

\let\ditto=\dittotikzA
\noindent
blah blah \ditto{} blah blah\\
blah blah \ditto[10em]{} blah blah\\

\let\ditto=\dittotikzB
\noindent
blah blah Test blah blah\\
blah blah \ditto{Test} blah blah\\
blah blah \ditto*{Test} blah blah\\
blah blah Testing testing blah blah\\
blah blah \ditto{Testing testing} blah blah\\
blah blah \ditto*{Testing testing} blah blah\\
blah blah \ditto{} blah blah\\
blah blah \ditto*{} blah blah\\
blah blah \ditto[10em]{Test} blah blah\\
blah blah \ditto*[10em]{Test} blah blah\\
blah blah \ditto[10em]{Testing testing} blah blah\\
blah blah \ditto*[10em]{Testing testing} blah blah\\
blah blah \ditto[10em]{} blah blah\\
blah blah \ditto*[10em]{} blah blah\\

\let\ditto=\dittoLatex
\noindent
blah blah Test blah blah\\
blah blah \ditto{Test} blah blah\\
blah blah \ditto*{Test} blah blah\\
blah blah Testing testing blah blah\\
blah blah \ditto{Testing testing} blah blah\\
blah blah \ditto*{Testing testing} blah blah\\
blah blah \ditto{} blah blah\\
blah blah \ditto*{} blah blah\\
blah blah \ditto[10em]{Test} blah blah\\
blah blah \ditto*[10em]{Test} blah blah\\
blah blah \ditto[10em]{Testing testing} blah blah\\
blah blah \ditto*[10em]{Testing testing} blah blah\\
blah blah \ditto[10em]{} blah blah\\
blah blah \ditto*[10em]{} blah blah\\

\end{document}

例子

一些相关问题:

答案1

您忘记了乘法符号。4\xfactor 不是 4*\xfactor。

\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{xparse}

\makeatletter

\usepackage{tikz}
\usetikzlibrary{math}
\newcommand\w{}
\newlength{\ditto@width}
\NewDocumentCommand\dittotikzB{ s O{1em} m }{%
    % #1 = starred means horizontal line along entire width, unstarred means no line (only ditto marks)
    % #2 = minimum width
    % #3 = string to use for calculating width
    \settowidth{\ditto@width}{#3}%
    %\show\ditto@width%
    \edef\w{\ifdim#2<\ditto@width\the\ditto@width\else\dimexpr#2\relax\fi}
    %\show\w%
    \begin{tikzpicture}[x=1ex,y=1ex,baseline=-.5ex,cap=round]
        \tikzmath{
            \xfactor = \w / 4 * 1pt/1ex;
            \yfactor = .175;
        };
        %\show\xfactor;
        %\show\yfactor;
        \IfBooleanT{#1}{% starred
            \draw (0,0) sin (1*\xfactor, \yfactor) cos (2*\xfactor, 0) sin (3*\xfactor, -\yfactor) cos (4*\xfactor, 0);
        };
        \draw[xshift=-.2ex, bend right=20] (2*\xfactor - .5, -.5) edge (2*\xfactor + .5, .5);
        \draw[xshift=.2ex, bend right=20] (2*\xfactor - .5, -.5) edge (2*\xfactor + .5, .5);
    \end{tikzpicture}%
}



\makeatother

\begin{document}

\let\ditto=\dittotikzB
\noindent
blah blah Test blah blah\\
blah blah \ditto{Test} blah blah\\
blah blah \ditto*{Test} blah blah\\
blah blah Testing testing blah blah\\
blah blah \ditto{Testing testing} blah blah\\
blah blah \ditto*{Testing testing} blah blah\\
blah blah \ditto{} blah blah\\
blah blah \ditto*{} blah blah\\
blah blah \ditto[10em]{Test} blah blah\\
blah blah \ditto*[10em]{Test} blah blah\\
blah blah \ditto[10em]{Testing testing} blah blah\\
blah blah \ditto*[10em]{Testing testing} blah blah\\
blah blah \ditto[10em]{} blah blah\\
blah blah \ditto*[10em]{} blah blah\\



\end{document}

相关内容