扩展 Tikz 矩形以填充剩余列宽

扩展 Tikz 矩形以填充剩余列宽

基于(更复杂)的例子扩展 Tikz 矩形以填充剩余文本宽度,如何为tikz以下 MWE 中的蓝色矩形分配宽度(列宽 文本(在此示例中为:“一些字幕”)?

在此处输入图片描述

\documentclass{article}
\usepackage[framemethod=TikZ]{mdframed}

%%%

\mdfdefinestyle{my_style_bla}{%
     linecolor=red,middlelinewidth=0.7pt, frametitlebackgroundcolor=red, apptotikzsetting={\tikzset{mdfframetitlebackground/.append style={%
shade,left color=red, right color=white}}}
}

%%%
 \newlength{\mycustomlength}
\settowidth\mycustomlength{abcdefghijklmnop}
%%%

\usepackage{tabularx}

\begin{document}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{mdframed}[style=my_style_bla,frametitle=\color{white}{Some Title}, nobreak=false]

%%%
%\begin{tabularx}{\textwidth}{@{} >{\NoMicrotype}l X@{}}
\begin{tabularx}{\textwidth}{@{}*{1}{p{\mycustomlength}}*{1}{X}@{}} % sub-headings modification
%%%

 & \textsc{Some Subtitle} \tikz[baseline=-0.5ex] \shade[left color=white, right color=white, middle color=blue] (0,0) rectangle (3,-0.05);
\\

%%%%%%
bla bla & \textbf{Item Title} \\
&\emph{yada yada description}
\\
\\
%%%%%%%
\end{tabularx}
\end{mdframed}

\end{document}

这就是(大致)我希望它在这个例子中看起来的样子:

在此处输入图片描述

答案1

您只需测量文本的宽度并从中减去即可\linewidth。通常情况下,我们会使用\dimexpr,但由于 TikZ 会通过 来运行所有内容\pgfmathparse,因此这里不需要它。

\documentclass{article}
\usepackage[framemethod=TikZ]{mdframed}

%%%

\mdfdefinestyle{my_style_bla}{%
     linecolor=red,middlelinewidth=0.7pt, frametitlebackgroundcolor=red, apptotikzsetting={\tikzset{mdfframetitlebackground/.append style={%
shade,left color=red, right color=white}}}
}

%%%
 \newlength{\mycustomlength}
\settowidth\mycustomlength{abcdefghijklmnop}
%%%

\usepackage{tabularx}

\begin{document}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{mdframed}[style=my_style_bla,frametitle=\color{white}{Some Title}, nobreak=false]

%%%
%\begin{tabularx}{\textwidth}{@{} >{\NoMicrotype}l X@{}}
\begin{tabularx}{\textwidth}{@{}*{1}{p{\mycustomlength}}*{1}{X}@{}} % sub-headings modification
%%%

 & \sbox0{\textsc{Some Subtitle}}\usebox0 \tikz[baseline=-0.5ex] \shade[left color=white, right color=white, middle color=blue]
   (0,0) rectangle ({\linewidth-\wd0},-0.05);
\\

%%%%%%
bla bla & \textbf{Item Title} \\
&\emph{yada yada description} \\
\\
%%%%%%%
\end{tabularx}
\end{mdframed}

\end{document}

演示

相关内容