0

Building on the (more complex) example of Expanding a Tikz rectangle to fill remaining text width, how could the blue tikz rectangle in the following MWE be assigned a width of (column width minus text (in this example: "Some Subtitle") ?

enter image description here

\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}

This is (roughly) what I'd like it to look like in this example:

enter image description here

1

You just have to measure the width of the text and subtract it from \linewidth. Normally one would use \dimexpr, but since TikZ runs everything through \pgfmathparse, you don't need it here.

\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}

demo

  • what is \sbox, usebox and \wd ? – nutty about natty Jun 27 '17 at 16:26
  • \savebox and \sbox create a box similar to \mbox, but save it in a box register. Registers 0-9 are not used by LaTeX itself, although it is safer to use them locally (inside a group). \usebox displays a box previously saved. More to the point, \wd, \ht and \dp return the width, height and depth of the box. Macros like \settowidth and \widthof actually use saveboxes to get the widths. – John Kormylo Jun 27 '17 at 19:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.