绘制带有阴影部分的对齐框

绘制带有阴影部分的对齐框

我想绘制几个带有垂直线分割的框,但到目前为止还不是很成功。

这是我迄今为止尝试的代码

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,shadows,arrows}
\usepackage{framed,graphicx,xcolor}
\begin{document}
\definecolor{shadecolor}{gray}{0.9}

\tikzstyle{block} = [draw, rectangle,color=gray, fill=gray!50, minimum height=4mm]
\tikzstyle{block1} = [draw, rectangle,minimum height=4mm, minimum width=40mm]
\tikzstyle{block2} = [draw, rectangle,minimum height=4mm, minimum width=45mm]
\begin{tikzpicture}
\node [block, minimum width=5mm] (11) {};
\node [block2, minimum width=45mm, right of =11,xshift=10mm] (12) {};

\node [block1, minimum width=5mm, below of =11] (21) {};
\node [block, minimum width=5mm, right of =21,xshift=-5mm] (22) {};
\node [block1, minimum width=40mm, right of =21,xshift=17.5mm] (20) {};

\node [block1, minimum width=10mm, below of =21] (31) {};
\node [block, minimum width=5mm, right of =31,xshift=-5mm] (32) {};
\node [block1, minimum width=35mm, right of =31, xshift=15mm] (30) {};

\node [block1, minimum width=15mm, below of =31] (41) {};
\node [block, minimum width=5mm, right of =41,xshift=-5mm] (42) {};
\node [block1, minimum width=30mm, right of =41, xshift=12.5mm] (40) {};

\node [block1, minimum width=20mm, below of =41] (51) {};
\node [block, minimum width=5mm, right of =51,xshift=2mm] (52) {};
\node [block1, minimum width=25mm, right of =51, xshift=17mm] (50) {};


\end{tikzpicture}
\end{document}

附图是我希望达到的结果!

在此处输入图片描述

有谁能帮我解决这个问题?或者有更好的方法吗?提前谢谢了。

[已编辑] 我已更新图片以澄清一些细节。也许图片本身并没有清楚地显示所有框的长度应相同且彼此对齐。每个条(框)中阴影部分的位置应使其看起来像是从一个槽滑动到另一个槽,中间没有空间或重叠。我想显示阴影部分在以下条中以相同的小步骤连续滑过它们。谢谢!

答案1

其他一些解决方案似乎相当复杂。您只需要一个循环。使用\Slider{<number>}绘制<number>+1带有移动滑块的条形图;条形图的宽度和高度可以分别使用\BarWd\BarHt来更改;滑块的宽度由 给出\SliderWd,连续条形图之间的垂直间距由 给出\BarSep

\documentclass{article}
\usepackage{tikz}

\newcommand\BarWd{6cm}
\newcommand\BarHt{10pt}
\newcommand\SliderWd{20pt}
\newcommand\BarSep{10pt}

\newcommand\Slider[1]{%
\begin{tikzpicture}
  \foreach \i in {0,1,...,#1}
  {
    \draw[fill=gray] (\i*\SliderWd,-\i*\BarHt-\i*\BarSep) rectangle +(\SliderWd-\pgflinewidth,\BarHt);
    \draw (0,-\i*\BarHt-\i*\BarSep) rectangle +(\BarWd-\pgflinewidth,\BarHt);
  }
\end{tikzpicture}%
}

\begin{document}

\noindent\Slider{3}\par\bigskip

\renewcommand\BarWd{\textwidth}
\renewcommand\BarHt{20pt}
\renewcommand\SliderWd{1.5cm}
\renewcommand\BarSep{20pt}

\noindent\Slider{6}

\end{document}

在此处输入图片描述

答案2

再一次尝试,将 MetaPost 代码包含在 LuaLaTeX 文件中,利用luamplibCTAN 上最新的软件包。

与 Gonzalo Medina 一样,我使用一个简单的循环和三个参数,即部分的宽度和高度,以及条形阴影部分的长度。此外,我假设我必须绘制尽可能多的条形,即阴影部分的最大数量。例如,如果条形长度为 7,滑块长度为 2,它将绘制3 = 7 div 2条形。

\documentclass{scrartcl}
\usepackage{luamplib}
    \mplibsetformat{metafun}
    \everymplib{%
        verbatimtex
            \leavevmode
        etex;
        u := 1cm; % Scale
        % Macro creating the bars
        def bars(expr width, height, shaded_width) =
            path bar, shaded_part;
            numeric n; n := width div shaded_width;
            for i=1 upto n:
                shaded_part := unitsquare xyscaled ((shaded_width, height)*u) 
                    shifted ((shaded_width, -1.5height)*(i-1)*u);
                fill shaded_part  withcolor 0.8white; 
                bar := unitsquare xyscaled ((width, height)*u) 
                    shifted (0, -1.5height*(i-1)*u);
                draw bar;
                % for not drawing the same lines twice
                if point 0 of bar <> point 0 of shaded_part:
                    draw point 0 of shaded_part -- point 3 of shaded_part;
                fi;
                if point 1 of bar <> point 1 of shaded_part:
                    draw point 1 of shaded_part -- point 2 of shaded_part;
                fi;
            endfor;
        enddef;
        beginfig(0)}
    \everyendmplib{endfig;}

\begin{document}
\begin{center}
    \begin{mplibcode}
        bars(8, 0.75, 2);
    \end{mplibcode}
    \par\vspace{3\bigskipamount}
    \begin{mplibcode}
         bars(5.5, 0.5, 1);
    \end{mplibcode}
\end{center}
\end{document}

酒吧

答案3

以这个时间轴制作器(Beamer 演示文稿中的时间线)开箱即用,无需任何更改,也无需tikz

\documentclass{article}
\usepackage{stackengine}
\renewcommand\useanchorwidth{T}
\usepackage{xcolor}
\def\theyearwidth{1.5pt}
\newlength\yrsfboxrule
\yrsfboxrule .4\fboxrule
\newcommand\yearwidth[1]{\def\theyearwidth{#1}\ignorespaces}
\newcommand\skipyears[2][white]{%
  \fboxrule\yrsfboxrule%
  \fboxsep=-\yrsfboxrule%
  \fcolorbox{gray}{#1}{\strut\hspace{#2}}%
  \ignorespaces%
}
\newcommand\showyear[2][black]{%
  \fboxsep=0pt%
  \stackon{%
    \colorbox{#1}{\strut\hspace{\theyearwidth}}%
  }{\sffamily\small#2}%
  \ignorespaces%
}
\begin{document}
\yearwidth{5mm}
\hspace{2mm}\showyear[gray]{}\skipyears{45mm}\par
\hspace{1.5mm}\skipyears{5mm}\showyear[gray]{}\skipyears{41mm}\par
\hspace{.5mm}\skipyears{10mm}\showyear[gray]{}\skipyears{38mm}\par
\skipyears{15mm}\showyear[gray]{}\skipyears{35mm}\par
\skipyears{23mm}\showyear[gray]{}\skipyears{28mm}\par
\end{document}

在此处输入图片描述

相关内容