3

I am currently trying to learn Latex with writing my CV with it. I am stuck at the point that I want to list my skills. I just want to have a simple function that takes a dynamic list of skills and creates a table out of it. I've read a lot of stuff using pggfor or etoolbox and more and I am kinda exhausted. Most of them are not easy to read and seem too complicated for a beginner.

\documentclass{article}
\begin{document}

\newcommand\createskill[2]{%
    \textsc{\textbf{#1}} & #2
}

\newcommand\createskills[1]{%
  \begin{tabular}{r|l}
    \makeatletter
    \@for\thisitem:=#1\do{\thisitem \\} %in the last iteration of loop a new line is added also 
    \makeatother
  \end{tabular}
}

% usage
\newcommand{\skillone}{\createskill{programming}{Python Java }}
\newcommand{\skilltwo}{\createskill{math}{Calculus Statistics}}
\createskills{\skillone, \skilltwo}
\end{document}

My problem is that because of \\ in the last iteration a new line is also added and I get a empty table row with only a sperator. I am open to suggestions to have a for loop that won't add this \\ in the last iteration.

the end result

I tried another solution with using \foreach command. Even though I got rid of the unnecessary \\ in the last row, this doesn't work well when contained within tabular environment.

\newcommand\createtablecontent[1]{%
    \foreach \x [count=\xi] in {#1} {\ifthenelse{\xi=1}{\x}{\\ \x}}
}

\newcommand\createskillsanothertry[1]{% called in the same way \createskills
    \begin{tabular}{r|l} 
      \createtablecontent{#1}
      \end{tabular}
}

enter image description here

with the above solution I only have the first row, and 22 warnings which seem quite complex.

If I exclude the tabular environment I have the desired behaviour of creating 2 lines of content.

\newcommand\createskillsanothertry[1]{%
      \createtablecontent{#1}
}

enter image description here

3
  • 4
    Please, show a minimal document from \documentclass to \end{document}.
    – egreg
    Commented Apr 15, 2020 at 10:37
  • Your code does not compile. I've suggested a solution to making dynamical tables, but I would be nicer to know if you're using packages or specific settings in order to avoid clashes.
    – user193767
    Commented Apr 15, 2020 at 11:11
  • @JairoADelRio I am trying to find the cause but couldn't find it. I picked the related commands to the problem from .cls file and the .tex file but it seems like it didn't work. Commented Apr 15, 2020 at 12:14

3 Answers 3

2

You can do it with expl3.

\documentclass{article}
\usepackage{xparse}

\ExplSyntaxOn

\NewDocumentCommand{\createskills}{m}
 {
  \begin{tabular}{r|l}
  \clist_map_function:nN { #1 } \irestmycase_skill:n
  \end{tabular}
 }

\cs_new_protected:Nn \irestmycase_skill:n
 {
  \tl_if_single:nTF { #1 }
   {
    \exp_last_unbraced:No \__irestmycase_skill_process:nn #1
   }
   {
    \__irestmycase_skill_process:nn #1
   }
 }
\cs_new_protected:Nn \__irestmycase_skill_process:nn
 {
  \textsc{#1} & #2 \\
 }

\ExplSyntaxOff

\begin{document}

% usage
\newcommand{\skillone}{{programming}{Python Java}}
\newcommand{\skilltwo}{{math}{Calculus Statistics}}
\createskills{\skillone, \skilltwo}

\bigskip

\createskills{
  {programming}{Python Java},
  {math}{Calculus Statistics}
}

\end{document}

enter image description here

1

We need not \directlua nor expl3 to solve this problem. The following solution is based only on TeX primitives:

\def\addto#1#2{\expandafter\def\expandafter#1\expandafter{#1#2}}
\def\skilllist{}
\def\createskill#1#2{\addto\skilllist{#1&#2\cr}}
\def\printskills{\vbox{\halign{\hfil\bf##\ \vrule\strut&\ ##\hfil\cr\skilllist}}}

\createskill{programming}{java python lua TeX}
\createskill{mathematics}{calculus statistics}
\createskill{languages}{english spanish korean}

\printskills

The \createskill macro adds the data to the internal \skillist in the form usable in \halign (table) parameter. And \printskills prints the table using \halign primitive and using the data from \skillist.

0

Using LuaLaTeX, in case this option is available, that's pretty easy. You only need two functions, \createskill and \printskill (you can rename them ad libitum). I've used TeX Gyre Schola only for displaying because it supports small caps.

%!TEX program = lualatex
%LuaLaTeX is mandatory here
\documentclass{standalone}
\usepackage{fontspec}
\setmainfont{TeX Gyre Schola}
\usepackage{luacode}
\begin{luacode*}
Skills = Skills or {}

function capitalise(str)
    local gmatch = unicode.utf8.gmatch
    local upper = unicode.utf8.upper
    local sub = unicode.utf8.sub
    local uppers = {}
    for w in str:gmatch("%S+") do
        table.insert(uppers, upper(sub(w,1,1))..sub(w,2))
    end
    return table.concat(uppers, " ")
end

function createskill(a,b)
    local str = [[\textbf{\textsc{]]..a..[[}} & ]]..capitalise(b)
    table.insert(Skills, str)
end

function printskills()
    tex.print([[\begin{tabular}{r|l}]])
    tex.print(table.concat(Skills, [[\\]]))
    tex.print([[\end{tabular}]])
end
\end{luacode*}
\newcommand{\createskill}[2]{\directlua{createskill("#1", "#2")}}
\newcommand{\printskills}{\directlua{printskills()}}
\begin{document}
%You add skills with this macro
\createskill{programming}{java python lua}
\createskill{mathematics}{calculus statistics}
\createskill{languages}{english spanish korean}
%And you print them all with this macro:
\printskills
\end{document}

enter image description here

1
  • 1
    I am not familiar with LuaLatex but i might give it a try if this is the only way and we can not find another solution which is simpler. Commented Apr 15, 2020 at 12:19

This site is temporarily in read-only mode and not accepting new answers.

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