0

I have a section in my document where writing space is limited and when there's a text entry that's too long, it does not look great because the points span two lines as shown in the first image below. Specifically, I would like to automatically enter a new line after the entries "Effective communication" or "International work experience" and have the points indented in the new line. For example, there should be a threshold for line length: in this case I want to set it to 20pt. I don't understand which \if to use and how to determine the length of the previous line to use it as a condition. If \if is not the way to go, is there any other way to do this?

I want to modify the following code snippet:

% \pointskill[<indent>]{<icon>}{<description>}{<points>}[<maxpoints>] creates
% | [indent] [icon]  description  \hfill  ● ● ● ○ ○ |
% -- inspired by arravc.cls by LianTze Lim: https://github.com/liantze/AltaCV
\NewDocumentCommand{\pointskill}{ O{0em} m m m O{5} }{%
    \hspace{#1} \cvicon{#2} ~ #3 \hfill%
    \ifdim#3<20pt\newline\hspace{20pt} \fi % my attempt to enter a new line, but I can't figure it out; #3 is the text entry variable
    \foreach \x in {1,...,#5}{%
        \space%
        {\ifnumgreater{\x}{#4}{\color{skillbg}}{\color{iconcolor}}% from etoolbox
        % don't use totalheight; see https://tex.stackexchange.com/a/41014
        \raisebox{0.5\height-0.4ex}{\scriptsize\faCircle}%
        }
    }\par%
}

EDIT: Here is the minimal working example. I trimmed it down as much as I could (.cls file was more than 600 lines). Essentially, I want to modify the command that starts with the line \NewDocumentCommand{\pointskill} in class.cls to automatically break lines if they are too long.

Current output:

enter image description here

Desired output*:

enter image description here

*I only want the entries from image1 that span multiple lines to be as in image2.

class.cls

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{class}[2020/02/09 CV class]

\RequirePackage[dvipsnames, svgnames, x11names]{xcolor}
% for positioning text within the side column | use showboxes for visible frame
\RequirePackage[absolute,overlay]{textpos}
% provides key-value class options via \DeclareOptionX
\RequirePackage{xkeyval}
% provides \ifnumgreater{<int expr.>}{<int expr.>}{<true>}{<false>},
% \apptocmd{<command>}{<code>}{<success>}{<failure>} and \newtoggle{<name>}
\RequirePackage{etoolbox}
% enable simple math like +/- etc. on lengths
\RequirePackage{calc}
% change page margins
\RequirePackage[
    nohead,
    nofoot,
    nomarginpar,
]{geometry}

% pre-define some colors the user can choose from
\definecolor{lightgreen}{rgb}{0.35,0.70,0.30}% lightgreen
\definecolor{shadygreen}{rgb}{0.20,0.50,0.20}% shadygreen
\definecolor{cvsidecolor}{HTML}{E7E7E7}
\definecolor{cvsectioncolor}{HTML}{0395DE}
\definecolor{cvsubsectioncolor}{HTML}{4D4D4D}
% set default values
\colorlet{maincolor}{lightgreen}
\colorlet{sidecolor}{cvsidecolor}
\colorlet{sectioncolor}{cvsectioncolor}
\colorlet{subsectioncolor}{cvsubsectioncolor}
\colorlet{itemtextcolor}{black!90}
% colors for document body (right column)
% let user define main color
\DeclareOptionX{maincolor}{\colorlet{maincolor}{#1}}
\DeclareOptionX{sidecolor}{\colorlet{sidecolor}{#1}}
\DeclareOptionX{sectioncolor}{\colorlet{sectioncolor}{#1}}
\DeclareOptionX{subsectioncolor}{\colorlet{subsectioncolor}{#1}}
\DeclareOptionX{itemtextcolor}{\colorlet{itemtextcolor}{#1}}

% set page margins
\newlength\sidebarwidth%
\newlength\topbottommargin%
\newlength\leftrightmargin%
\newlength\sidebartextwidth
% default values
\setlength{\sidebarwidth}{0.34\paperwidth}
\setlength{\topbottommargin}{0.02\paperheight}
\setlength{\leftrightmargin}{0.02\paperwidth}
% user overwrites
\DeclareOptionX{sidebarwidth}{\setlength{\sidebarwidth}{#1}}
\DeclareOptionX{topbottommargin}{\setlength{\topbottommargin}{#1}}
\DeclareOptionX{leftrightmargin}{\setlength{\leftrightmargin}{#1}}

% show sidebar and page margins
\newtoggle{tshowframes}
\togglefalse{tshowframes}
\DeclareOptionX{showframes}{
    \geometry{showframe}
    \TPoptions{showboxes=true}
    \toggletrue{tshowframes}
    % adding \hline in \newenvironment directly doesn't work, so do it here...
    \AtBeginDocument{\apptocmd{\personaldata}{\hline}{}{}}
}

% draw vertical guideline
\newcommand{\plotvline}{}
\DeclareOptionX{vline}{%
    % must be defined here as macro, b/c tikz won't expand absolute length in
    % \backgroundsetup -- BUG?
    \renewcommand{\plotvline}{%
        \draw [thick, red, opacity=0.7]
        (\leftrightmargin + #1, 0) -- (\leftrightmargin + #1, -\paperheight);
    }
}

% pass further options to base class and load it
\DeclareOptionX*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptionsX\relax
\LoadClass{article}

% compute "inner" margin of sidebar automatically;
% must come after \sidebarwidth and \leftrightmargin possibly changed by user
\setlength{\sidebartextwidth}{\sidebarwidth - 2\leftrightmargin}

% let geometry package perform the changes;
% must come after loading the base class to prevent overwriting
\geometry{
    top=\topbottommargin,
    bottom=\topbottommargin,
    left=\sidebarwidth + \leftrightmargin,
    right=\leftrightmargin,
}

%-------------------------------------------------------------------------------
%                              REQUIRED PACKAGES
%-------------------------------------------------------------------------------
% font configuration
\RequirePackage[sfdefault]{ClearSans}

% use as workaround for spacing problem when TikZ picture is not in paragraph;
% details: https://tex.stackexchange.com/a/435790
\RequirePackage[texcoord]{eso-pic}

% for easy section style definitions
\RequirePackage{titlesec}

% loads graphicx, provides align=c option for vertical alignment w.r.t. text
\RequirePackage{graphbox}

% provides X column type for automatic length calculations
\RequirePackage{tabularx}

% take care of compiler-specific packages
\RequirePackage{ifluatex}
\RequirePackage{ifxetex}
\newif\ifxetexorluatex
\ifxetex
    \xetexorluatextrue
\else
    \ifluatex
        \xetexorluatextrue
    \else
        \xetexorluatexfalse
    \fi
\fi

% pictures, icons and drawings
\ifxetexorluatex
    \RequirePackage{fontawesome5}
    \RequirePackage{academicons}
\else
    \RequirePackage{fontawesome}
\fi
\RequirePackage{tikz}
\usetikzlibrary{arrows, backgrounds}

% provides \xrfill for horizontal rules
\RequirePackage{xhfill}

% provides basic conditional expressions
\RequirePackage{ifthen}

% enable multiple optional arguments in macros
\RequirePackage{xparse}

%-------------------------------------------------------------------------------
%                          DERIVED COLOR DEFINITIONS
%-------------------------------------------------------------------------------
% profile section color (sidebar/left column)
\colorlet{pseccolor}{maincolor!90}
% color used for all icon arguments
\colorlet{iconcolor}{maincolor!90}

\colorlet{skillbg}{black!25}


%-------------------------------------------------------------------------------
%                      GLOBAL LAYOUT AND HEADINGS STYLE
%-------------------------------------------------------------------------------
% remove headers and footers
\pagestyle{empty}

% globally disable paragraph indentation
\setlength{\parindent}{0pt}

% creates a rule after some text using remaining line width
% usage: \xrfill[<raise>]{<width>}
\newcommand*{\sectionline}[1]{#1~\xrfill[.5ex]{1pt}[pseccolor]}


% uniform icon style for all skill icons, e.g. flags or fontawesome icons
\newcommand{\cvicon}[1]{\makebox[1em]{\color{iconcolor} #1}}

% \pointskill[<indent>]{<icon>}{<description>}{<points>}[<maxpoints>] creates
% | [indent] [icon]  description  \hfill  ● ● ● ○ ○ |
% -- inspired by arravc.cls by LianTze Lim: https://github.com/liantze/AltaCV
\NewDocumentCommand{\pointskill}{ O{0em} m m m O{5} }{%
    \hspace{#1} \cvicon{#2} ~ #3 \hfill%
    %\ifdim#3<20pt\newline\hspace{20pt} \fi % my attempt to enter a new line, but I can't figure it out; #3 is the text entry variable
    \foreach \x in {1,...,#5}{%
        \space%
        {\ifnumgreater{\x}{#4}{\color{skillbg}}{\color{iconcolor}}% from etoolbox
        % don't use totalheight; see https://tex.stackexchange.com/a/41014
        \raisebox{0.5\height-0.4ex}{\scriptsize\faCircle}%
        }
    }\par%
}


%-------------------------------------------------------------------------------
%                               SIDEBAR LAYOUT
%-------------------------------------------------------------------------------
% draw sidebar background on current page
\newcommand{\drawSidebarBG}{%
    \AddToShipoutPictureBG*{%
        \begin{tikzpicture}[remember picture, overlay]
            \node[
                rectangle,
                fill=sidecolor,
                anchor=north west,
                minimum width=\sidebarwidth,
                minimum height=\paperheight,
            ]{};%
            % plot vertical red guideline
            \plotvline%
        \end{tikzpicture}%
    }%
}

% use textpos to position textblock within TikZ background; we have to use
% the starred version for absolute values here, b/c we use \pagewidth directly
% instead of \setlength{\TPHorizModule}{<dimen>}, which seems to be "absolute"
% as opposed to "relative" - strange but true.
\newenvironment{sidebar}{%
    \drawSidebarBG%
    \begin{textblock*}{\sidebartextwidth}(\leftrightmargin, \topbottommargin)
}{%
    \end{textblock*}%
}

% provide user interface for easily adding new sections in side bars
% default: empty sidebar
\newcommand{\frontsidebar}{}
\newcommand{\addtofrontsidebar}[1]{\apptocmd{\frontsidebar}{#1}{}{}}

\newcommand{\makefrontsidebar}{%
    \begin{sidebar}
        % most sidebar commands end with \par; increase space between them
        \setlength{\parskip}{1ex}

        % user definitions
        \frontsidebar
    \end{sidebar}
}

example.tex

\documentclass[
    a4paper,
    maincolor=shadygreen,
    sectioncolor=lightgreen,
]{class}

% improve word spacing and hyphenation
\usepackage{microtype}
\usepackage{ragged2e}

% take care of proper font encoding
\ifxetexorluatex
    \usepackage{fontspec}
    \defaultfontfeatures{Ligatures=TeX}
\else
    \usepackage[utf8]{inputenc}
    \usepackage[T1]{fontenc}
\fi

\addtofrontsidebar{
        \pointskill{\faBolt}{Effective communication}{5}[5]
        \pointskill{\faChild  \faUsers}{International work experience}{4}[5]
        \pointskill{\faToggleOn}{Living abroad}{5}[5]
        \pointskill{\faGavel}{IPR}{3}[5]
        \pointskill{\faAngellist}{Project coordination}{3}[5]
        \pointskill{\faBalanceScale}{Ethics}{5}[5]
}

\begin{document}

\makefrontsidebar

\end{document}

4
  • 1
    Please always provide full minimal examples not sniplets like this that uses various packages that are not listed in the sniplet. Then it is easier for others to test your code.
    – daleif
    Oct 12, 2022 at 9:25
  • @daleif I used a template which has a lengthy .cls file. Is it ok if I paste the whole thing?
    – inot12
    Oct 12, 2022 at 9:36
  • 1
    @inot12 No, only post the relevant parts, so it is a minimal working example (MWE).
    – dexteritas
    Oct 12, 2022 at 9:45
  • Please also add an image of the output plus an image of the desired output. Paint does the job. Foremost, make the example minimal. It's currently maximal. Oct 12, 2022 at 10:51

1 Answer 1

0

You can use \settowidth{length register}{content} from the calc package to store the width of some content as a length (in pt).

MWE:

\documentclass[10pt,ragged2e]{altacv}
\usepackage{calc}
\usepackage{paracol}
\usepackage[sfdefault]{ClearSans}

\newcommand{\cvicon}[1]{\makebox[1.5em]{\color{accent}#1}}
\newlength{\skillswidth}
\NewDocumentCommand{\pointskill}{ O{0em} m m m O{5} }{%
    \hspace{#1} \cvicon{#2} ~ #3 \hfill%
    \settowidth{\skillswidth}{#3}%
    \ifdim\skillswidth>100pt\newline\hspace{22pt}\fi
    \foreach \x in {1,...,#5}{%
        \space%
        {\ifnumgreater{\x}{#4}{\color{body!30}}{\color{accent}}%
        \scriptsize\faCircle%
        }
    }\par%
}

\begin{document}
\columnratio{0.45}
\definecolor{accent}{rgb}{0.20,0.50,0.20}

\begin{paracol}{2}
\cvsection{Skills}
\pointskill{\faBolt}{Effective communication}{5}[5]
\pointskill{\faChild\faUsers}{International work experience}{4}[5]
\pointskill{\faToggleOn}{Living abroad}{5}[5]
\pointskill{\faGavel}{IPR}{3}[5]
\pointskill{\faAngellist}{Project coordination}{3}[5]
\pointskill{\faBalanceScale}{Ethics}{5}[5]
\end{paracol}
\end{document}

Doesn't look great though. The bullets on the new line seem bigger and further apart (even though they are exactly the same as the other rows).

enter image description here


I would opt for manual linebreaks instead:

\documentclass[10pt,ragged2e]{altacv}
\usepackage{calc}
\usepackage{paracol}
\usepackage[sfdefault]{ClearSans}

\newcommand{\cvicon}[1]{\makebox[1.5em]{\color{accent}#1}}
\NewDocumentCommand{\pointskill}{ O{0em} m m m O{5} }{%
    \hspace{#1} \cvicon{#2} ~ #3\hfill%
    \foreach \x in {1,...,#5}{%
        \space%
        {\ifnumgreater{\x}{#4}{\color{body!30}}{\color{accent}}%
        \scriptsize\faCircle%
        }
    }\par%
}

\begin{document}
\columnratio{0.45}
\definecolor{accent}{rgb}{0.20,0.50,0.20}

\begin{paracol}{2}
\cvsection{Skills}
\pointskill{\faBolt}{Effective\\\hspace{26pt}communication}{5}[5]
\pointskill{\faChild\faUsers}{International\\\hspace{26pt}work experience}{4}[5]
\pointskill{\faToggleOn}{Living abroad}{5}[5]
\pointskill{\faGavel}{IPR}{3}[5]
\pointskill{\faAngellist}{Project coordination}{3}[5]
\pointskill{\faBalanceScale}{Ethics}{5}[5]
\end{paracol}
\end{document}

enter image description here

2
  • Note that I heavily minimized the example by cutting out the custom class and using altacv (on which the custom class is based) instead.
    – Marijn
    Oct 12, 2022 at 11:58
  • @ Marijn Thank you very much. This was exactly what I was looking for. The problem for me is that I don't really undestand the logic behind conditionals in Latex.
    – inot12
    Oct 12, 2022 at 12:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .