# Tikz Draw Element At The Top Aligned Relative To Element At The Bottom

I am trying to make a Latex command which allows me to deploy some kind of progress bars. Ideally something like this is the goal:

As a side note, I'll probably replace this progress bar later with arrows or something. Anyway, here is the relevent code thus far

    \documentclass{article}
\RequirePackage{tikz}
\usetikzlibrary{arrows, backgrounds}

\definecolor{cvblue}{HTML}{0E5484}
\colorlet{maincolor}{cvblue}
\colorlet{skillbg}{black!25}
\colorlet{iconcolor}{maincolor!90}

\newlength\sidebarwidth%
\newlength\topbottommargin%
\newlength\leftrightmargin%
\newlength\sidebartextwidth

\setlength{\sidebarwidth}{0.34\paperwidth}
\setlength{\topbottommargin}{0.02\paperheight}
\setlength{\leftrightmargin}{0.02\paperwidth}
\setlength{\sidebartextwidth}{\sidebarwidth - 2\leftrightmargin}

\newcommand{\logo}[1]{\includegraphics[align=c, width=1.5em]{#1}}

\newcommand{\barskilltwo}[4]{
% remove 1pt in width to prevent overfull box warnings
\begin{tikzpicture}[x=\sidebartextwidth-1pt, y=2ex]
\draw[fill, skillbg, rounded corners=0.5em]
(0, 0) rectangle (1, 1) node[midway][text=black] {#4};
\draw[fill, iconcolor!70, rounded corners=0.5em]
(0, 0) rectangle (#3/100, 1);
\node[above right] at (0, 1) {\cvicon{#1} ~ #2};
\end{tikzpicture}
\par
}

\begin{document}
\barskilltwo{\logo{pics/tech_languages/c++.png}}{C++}{100}{Six Years}
\barskilltwo{\logo{pics/tech_languages/python.png}}{Python}{100}{Six Years}
\barskilltwo{\logo{pics/tech_languages/c.png}}{C}{45}{Three Years}
\barskilltwo{\logo{pics/tech_languages/java.png}}{Java}{20}{Two Years}
\barskilltwo{\logo{pics/tech_languages/csharp_purple.png}}{C\#}{10}{One Year}
\end{document}


And here is the effect:

As you can see, there is a problem in that the text is hidden by the second blue bar.

My goal is to have text which is on top of all other elements, but is aligned relative to the midpoint of bottom element via node[midway]

Is such a thing possible? What is the best way to achieve the effect described in the first screenshot?

I have also tried to create a new node like so:

    \newcommand{\barskilltwo}[4]{
% remove 1pt in width to prevent overfull box warnings
\begin{tikzpicture}[x=\sidebartextwidth-1pt, y=2ex]
\draw[fill, skillbg, rounded corners=0.5em]
(0, 0) rectangle (1, 1);
\draw[fill, iconcolor!70, rounded corners=0.5em]
(0, 0) rectangle (#3/100, 1);
\node[above right] at (0, 1) {\cvicon{#1} ~ #2};
\node[midway][text=black] {#4};
\end{tikzpicture}
\par
}


But this would need manual alignment and is not guaranteed to be aligned with the midpoint of the bottom element.

This can be solved with an extra node at the bottom:

\node(text) at (0.5,0.5){#4};


But I suspect I might run into alignment issues later on if I wanted to resize the bar for example. Is there a way to get this perfectly relative to the bottom node width midpoint?

Any help would be much appreciated. Thank you for reading.

• Have you tried defining the text that appears with the progress bar as a node label instead of the node contents? – Plergux Oct 24 at 12:10
• I'm not so sure how to use labels, I couldn't get them to stay in a guaranteed place. Actually it can be solved with a command at the bottom: " \node(text) at (0.5,0.5){#4}; " but this 0.5,0.5 is a little ad-hoc. Either way it works. Perhaps this can be closed – Joshua Viggiani Oct 24 at 12:51
• Split the line that draws the grey bar into two pieces, one that draws the grey bar as you have it and which places a coordinate at the correct place, then after the blue bar is drawn have the node command and use the coordinate for positioning. – Andrew Stacey Oct 24 at 13:01