TransWikia.com

How to draw vertical line with exactly the height of a parbox next to it

TeX - LaTeX Asked by owmal on March 8, 2021

I am trying to create small sections for a cv where the section name and a vertical line should be next to the content. The section name should be centered and the vertical line should be exactly the height of the content. This is the desired output:

enter image description here

Now with my code, I don’t know how to set the vertical line height to get exactly the height of the parbox. This is why for demonstration, I’ve set this to 1cm. Does anyone know how to get my desired output with small modifications to my code or an even better way to achieve this?

documentclass[12pt]{standalone}

usepackage{tikz}

newcommand{lorem}{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus.}

newcommand{customsection}[2]{
    begin{minipage}{0.05textwidth}
        rotatebox[origin=c]{90}{#1}
        hspace{0.01cm}
        begin{tikzpicture}
            fill [bottom color=red, top color=blue] (0cm, 0cm) rectangle (-0.05cm, 1cm);
        end{tikzpicture}
    end{minipage}
    parbox[c]{0.85textwidth}{
        #2
    }
}


begin{document}
    customsection{TEST}{lorem  lorem  lorem}
end{document}

I have also tried accessing the parbox height, which did not work for me:
Access height of a parbox

Thanks in advance.

My output:
enter image description here

One Answer

How about the following code? Documentation is provided in the code as comments.

documentclass[12pt]{standalone}

usepackage{tikz}

newcommand{lorem}{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus.}

% Define owmal's box to store the parbox
newsaveboxowmalsbox

% Notice where `%' are added to suppress end-of-line spaces!
newcommand{customsection}[2]{%
% First we save parbox into owmalsbox.
% We also use strut both at the beginning and at the end,
% and this will ensure that the first line and the last line
% have the same height (in most cases).
    sboxowmalsbox{%
        parbox[c]{0.85textwidth}{%
            strut#2strut
        }%
    }%
% The total height of the parbox is now available as
% thehtowmalsbox+thedpowmalsbox, so we can put our
% side-way text at (thehtowmalsbox+thedpowmalsbox)/2,
% and draw our rectangle accordingly. The minipage has the
% optional argument `c' to go with `parbox[c]...' above.
% Notice again the use of strut in the side-way text.
    begin{minipage}[c]{0.05textwidth}
        begin{tikzpicture}
            node [rotate=90, above] at
                (-0.05cm, {(thehtowmalsbox+thedpowmalsbox)/2})
                    {strut#1};
            fill [bottom color=red, top color=blue]
                (0cm, 0cm)
                    rectangle
                (-0.05cm, thehtowmalsbox+thedpowmalsbox);
        end{tikzpicture}%
    end{minipage}%
% The following additional space depends on how you setup
% the minipage (it is 0.05textwidth wide for now).
% Adjust these if necessary.
    hspace{0.5cm}%
% Finally we typeset owmalsbox by releasing its content
% (and also destroy its content).
    unhboxowmalsbox
}

begin{document}
    customsection{TEST}{lorem  lorem  lorem}
end{document}

customsection

Correct answer by Ruixi Zhang on March 8, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP