0

I am quite new to LaTeX and have been using it mostly to write up my assignments. I have since taken on the challenge to re-write my resume using LaTeX too and I have grown quite fond of the twentyseondscv template, which can be found here.

The template is mostly quite user-friendly, even for a novice like myself, but I have one small issue - the resume allows for skills to be shown as a score, out of 6, and this score is translated into a bar. For example, if you had a skill with a score of 6, it would colour the entire bar.

The code for the template is extremely long, so I reproduce the portion of the code relating to the skills bars below:

\newcommand\skills[1]{ 
    \renewcommand{\skills}{
        \begin{tikzpicture}
            \foreach [count=\i] \x/\y in {#1}{
                \draw[fill=maingray,maingray] (0,\i) rectangle (6,\i+0.4);
                \draw[fill=white,mainblue](0,\i) rectangle (\y,\i+0.4);
                \node [above right] at (0,\i+0.4) {\x};
            }
        \end{tikzpicture}
    }
}

However, I find that a score, out of 6, is rather "weird" and would like it to be out of 5 instead. I tried to play around with the code, such as by changing the "6" to a "5", but that merely shortens the bar - it simply removes the last 1/6 of the bar. Instead, what I want is for the bar to be the same length, but for it to be "cut" into 5 portions, instead of 6, such that if I put a skill of a score of 1, it should shade 1/5 of the bar, not 1/6, which it currently does.

How can I tweak the code above to reflect this? I would suppose the change(s) should be very minor and easy, although as mentioned at the start, I am very new to LaTeX, so any help would be greatly appreciated!

5
  • 3
    I cannot test this, as I cannot access the template, but usually the default length in tikz is 1cm. You can change the 6 to 5 and add ‘[y=1.2cm]’ after ‘\begin[tikzpicture]’. That should stretch it to the original length but calculate everything out of 5.
    – Markus G.
    Jun 12, 2021 at 15:56
  • @MarkusG. Oh yes! Thank you so much! Your answer was not quite right - adding [y=1.2cm] increased the width of the bar, not the length, so I obviously tried [x=1.2cm] and then it worked, but yes, you solved my issue nonetheless! :) I have posted an edit with credits to you!
    – Ethan Mark
    Jun 12, 2021 at 16:02
  • Oh yes, sorry I keep messing x and y up. Glad I could help.
    – Markus G.
    Jun 12, 2021 at 16:03
  • Instead of adding the answer to the question, I suggest either @MarkusG. or yourself add a "proper" answer. Jun 12, 2021 at 16:05
  • @TorbjørnT. Yes, that is probably wiser and I have done so!
    – Ethan Mark
    Jun 12, 2021 at 16:08

1 Answer 1

4

As requested, here my answer, with a comparison of the original code and the “out of 5” version.

As I mentioned in the comments above, the default length for tikz is 1cm in both x and y directions. They can be modified by adding the respective options to the environment. To get from out of 6 to out of 5, but with the original length, you need a factor of 1.2. Hence, adding the option x=1.2cm stretches everything by the required amount. Additionally, the maximum length of the rectangle needs to be shortened from 6 to 5 to account for the changes.

Here is the code:

\documentclass{scrartcl}
\usepackage{tikz}

%The original command
\newcommand\skillsorig[1]{
        \begin{tikzpicture}
           \foreach [count=\i] \x/\y in {#1}{
                \draw[fill=gray,gray] (0,\i) rectangle (6,\i+0.4);
                \draw[fill=white,blue](0,\i) rectangle (\y,\i+0.4);
                \node [above right] at (0,\i+0.4) {\x};
            }
       \end{tikzpicture}
}

%The new command
\newcommand\skills[1]{
        \begin{tikzpicture}[x=1.2cm]
           \foreach [count=\i] \x/\y in {#1}{
                \draw[fill=gray,gray] (0,\i) rectangle (5,\i+0.4);
                \draw[fill=white,blue](0,\i) rectangle (\y,\i+0.4);
                \node [above right] at (0,\i+0.4) {\x};
            }
       \end{tikzpicture}
}

\begin{document}
    %Out of 6
    \skillsorig{{name/4.8}}
    
    %Out of 5
    \skills{{name/4}}
\end{document}

Note that I removed the renewcommand part of the code as it is not required outside of the template and replaced the colours with default ones.

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.