更新 3

更新 3

我想知道是否有一种标准化和奇特的方式来拥有像这些水平线性的在 LaTeX 文章中。有人知道我应该如何开始解决这个问题吗?我想得到一个占用文本空间的水平滑块,而不是浮动的。到目前为止,我还没有解决这个问题,我不知道如何在它上面放置一个正方形+三角形的形状:

 \documentclass{article}
 \usepackage{xcolor}
 \usepackage{tikz}
 \begin{document}
 SLIDER \tikz{\path[draw=lightgray,fill=lightgray, rounded corners] (0,0) rectangle (2.5cm,0.2cm);}
 \end{document}

答案1

第一次尝试:

\usetikzlibrary{calc}

\def\SLIDER#1#2{% 1: length, 2: position of the mark (0 to 1)
\tikz[baseline=-0.1cm]{
 \coordinate (start) at (0,0);
 \coordinate (end) at (#1,0);
 \coordinate (mark) at ($(start)!#2!(end)$);
 \draw[line width=0.2cm, line cap=round, lightgray] (start) -- (end);
 \shade[ball color=blue!30!cyan] (mark) circle(0.15cm);
}
}

SLIDER \SLIDER{2.5cm}{0.7}

结果

更新:第二次尝试

在栏中浮雕阴影效果,更多类型或标记:

\usetikzlibrary{calc}


\def\CircleSLIDER#1#2{% 1: length, 2: position of the mark (0 to 1)
\tikz[baseline=-0.1cm]{
 \coordinate (start) at (0,-0.1cm);
 \coordinate (end) at (#1,0.1cm);
 \coordinate (mark) at ($(start|-0,0)!#2!(end|-0,0)$);
 \fill[rounded corners=0.1cm, draw=gray, bottom color=lightgray, top color=black, middle color=lightgray] (start) rectangle (end);
 \shade[draw=darkgray, rounded corners=0.2mm, ball color=blue!20!cyan] (mark) circle(.15) ;
}
}

\def\SquareSLIDER#1#2{% 1: length, 2: position of the mark (0 to 1)
\tikz[baseline=-0.1cm]{
 \coordinate (start) at (0,-0.1cm);
 \coordinate (end) at (#1,0.1cm);
 \coordinate (mark) at ($(start|-0,0)!#2!(end|-0,0)$);
 \fill[rounded corners=0.1cm, draw=gray, bottom color=lightgray, top color=black, middle color=lightgray] (start) rectangle (end);
 \shade[draw=darkgray, rounded corners=0.2mm, ball color=blue!20!cyan] (mark) +(-.15,-.15) rectangle +(.15, .15) ;
}
}
\def\TriangleSLIDER#1#2{% 1: length, 2: position of the mark (0 to 1)
\tikz[baseline=-0.1cm]{
 \coordinate (start) at (0,-0.1cm);
 \coordinate (end) at (#1,0.1cm);
 \coordinate (mark) at ($(start|-0,0)!#2!(end|-0,0)$);
 \fill[rounded corners=0.1cm, draw=gray, bottom color=lightgray, top color=black, middle color=lightgray] (start) rectangle (end);
 \shade[draw=darkgray, rounded corners=0.2mm, ball color=blue!20!cyan] (mark) ++(-.15,-.15) -- ++(.15,-.15) -- ++(.15,.15) -- ++(0,.3) -- ++(-.3,0) -- cycle ;
}
}

\CircleSLIDER{2.5cm}{0.4}

\SquareSLIDER{2.5cm}{0.7}

\TriangleSLIDER{2.5cm}{0.3}

结果2

更新 2

现在考虑了阴影、渐变和反射出格在UI设计中,也许你更喜欢这个版本:

\usetikzlibrary{calc}


\def\CircleSLIDER#1#2{% 1: length, 2: position of the mark (0 to 1)
\tikz[baseline=-0.1cm]{
 \coordinate (start) at (0,-0.1cm);
 \coordinate (end) at (#1,0.1cm);
 \coordinate (mark) at ($(start|-0,0)!#2!(end|-0,0)$);
 \fill[rounded corners=0.1cm, draw=gray, fill=lightgray] (start) rectangle (end);
 \fill[draw=gray, rounded corners=0.2mm, fill=blue!20!cyan] (mark) circle(.15) ;
}
}

\def\SquareSLIDER#1#2{% 1: length, 2: position of the mark (0 to 1)
\tikz[baseline=-0.1cm]{
 \coordinate (start) at (0,-0.1cm);
 \coordinate (end) at (#1,0.1cm);
 \coordinate (mark) at ($(start|-0,0)!#2!(end|-0,0)$);
 \fill[rounded corners=0.1cm, draw=gray,fill=lightgray] (start) rectangle (end);
 \fill[draw=gray, rounded corners=0.2mm, fill=blue!20!cyan] (mark) +(-.15,-.15) rectangle +(.15, .15) ;
}
}
\def\TriangleSLIDER#1#2{% 1: length, 2: position of the mark (0 to 1)
\tikz[baseline=-0.1cm]{
 \coordinate (start) at (0,-0.1cm);
 \coordinate (end) at (#1,0.1cm);
 \coordinate (mark) at ($(start|-0,0)!#2!(end|-0,0)$);
 \fill[rounded corners=0.1cm, draw=gray, fill=lightgray] (start) rectangle (end);
 \fill[draw=gray, rounded corners=0.2mm, fill=blue!20!cyan] (mark) ++(-.15,-.15) -- ++(.15,-.15) -- ++(.15,.15) -- ++(0,.3) -- ++(-.3,0) -- cycle ;
}
}

结果3

更新 3

最后一个,我保证:-)

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,shadows,shadows.blur}

\def\IosSevenSlider#1#2{
    \tikz[baseline=-0.1cm]{
        \coordinate (start) at (0,0);
        \coordinate (end) at (#1,0);
        \coordinate (mark) at ($(start)!#2!(end)$);
        \useasboundingbox (start|- 0,-.25) rectangle (end|- 0, .25);
        \draw[line width=0.4mm, line cap=round, blue!50!cyan] 
             (start) -- (mark) edge[lightgray] (end);
        \node[fill=white, draw=lightgray, very thin,
            blur shadow={shadow xshift=0pt, shadow opacity=20, shadow yshift=-0.9mm,
                         shadow blur steps=6, shadow blur radius=0.3mm},
            circle, minimum size=0.25cm, inner sep=0pt] at (mark) {};
    }
}


\begin{document}
\setlength{\fboxsep}{0pt}
\fbox{\IosSevenSlider{2.5cm}{0.7}}
\end{document}

结果4

答案2

基于 JLDiaz 的第一次尝试:

\documentclass{article}
\usepackage{xcolor}
\usepackage{tikz}
\begin{document}
\usetikzlibrary{calc}

\def\SLIDER#1#2{% 1: length, 2: position of the mark (0 to 1)
\tikz[baseline=-0.1cm]{
    \coordinate (start) at (0,0);
    \coordinate (end) at (#1,0);
    \coordinate (mark) at ($(start)!#2!(end)$);
    \draw[line width=0.2cm, line cap=round, lightgray] (start) -- (end);
    \path[
        fill=blue!30!cyan,
    ] (mark) + (-.15cm, -.1cm) -- +(0cm, -.2cm) -- +(.15cm, -.1cm) -- +(.15cm, .2cm) -- +(-.15cm, .2cm) -- cycle;
}}

SLIDER \SLIDER{2.5cm}{0.7}
\end{document}

相关内容