This is another tcolorbox solution which uses the skins
and xparse
libraries. xparse is used to define a new command
\namebox{<first names>}{<last name>}{<content of right hand box e.g. list>}
The width of the left hand box is adapted to fit the content of the top and bottom parts. The overall structure consists of a sidebyside
box which adapts to the width of the left hand box. The left hand side of the box consists of a further tcolorbox
with upper and lower parts. The right hand side of the box consists of whatever is in the third argument - in this case, a list.
This is probably easier to demonstrate than it is to explain:
\namebox{First Names}{Last Name}{%
\begin{itemize}
\item[\faGithubSquare] github.com/Repository
\item[\faLinkedinSquare] linkedin.com/Account
\item[\faMobile] 0123 456789
\end{itemize}%
}
In this case, the first argument takes more width than the second, so the left hand side will be set to accommodate the width of First Names
.
\namebox{Short Name}{Somewhat Longer Name}{%
\begin{itemize}
\item[\faGithubSquare] github.com/Repository
\item[\faLinkedinSquare] linkedin.com/Account
\item[\faMobile] 0123 456789
\end{itemize}%
}
In this case, the second argument needs more space than the first, so the left hand box will be sized to accommodate Somewhat Longer Name
.
In both cases, the remainder of the line width will be available for the content of the right hand side i.e. in this case the list with icons.
\DeclareRobustCommand{\nameboxfont}{\normalfont\sffamily\bfseries\Large\baselineskip14pt}
sets the font which will be used for the content of the boxes. Adapt as desired.
Two styles are defined which determine the styles used for the boxes.
\tcbset{%
name box/.style={%
This style is used for the two-storey box on the left.
colback=black,
Black background.
lower separated=false,
No line separating the upper bit from the lower.
coltext=white,
White text.
fontupper=\nameboxfont,
fontlower=\nameboxfont,
Applies the font defined earlier to both parts of the box.
halign=center,
halign lower=center,
Aligns the text in the upper and lower stories centred.
sharpish corners,
The default is to use rounded corners. I've used sharpish corners
here. Another possibility is sharp corners
. Try to see which you like.
middle=.75mm,
Although the manual suggests otherwise, this seems to be half the distance between the upper and lower parts of the box. (The manual suggests this is in addition to boxsep
, but that seems not to be the case.)
},
That's that style done.
two by two/.style={%
This is the style for the big box which includes everything.
sidebyside gap=1mm,
The distance between the left hand black box and the right hand side containing the list.
lower separated=false,
As above: no line.
halign upper=left,
halign lower=left,
Sets the alignment of the left black box left
and the alignment of the right hand list to left
.
sidebyside adapt=left,
Adapts the width of the parts to the width of the stuff on the left.
empty,
No background, lines etc.
size=minimal,
Don't add extra spacing.
This box is purely structural: its purpose is to align things and not to look like a box in anyway, so we want this stripped-down 'bare' version provided by the library skins
.
},
We're done with this style, too.
}
That's all the styles we need.
We also want a couple of scratch dimensions for when we measure things.
\newlength\nameboxtempa
\newlength\nameboxtempb
Here's the definition of the final command, \namebox{}{}{}
.
\NewDocumentCommand \namebox { m m +m }{%
\settowidth\nameboxtempa{\nameboxfont #1}%
\settowidth\nameboxtempb{\nameboxfont #2}%
We measure the widths of the first and second arguments.
\ifdim\nameboxtempa<\nameboxtempb\setlength\nameboxtempa{\nameboxtempb}\fi%
We now compare the widths. If the width of the stuff in the bottom (last name) is greater than the width of the stuff in the top (first names), then we set the width \nameboxtempa
to the width of the bottom bit. Otherwise, \nameboxtempa
is already the width we want.
\tcbsidebyside[two by two]{%
Apply our style for the big box.
\begin{tcolorbox}[%
Start the box on the left.
name box,
Apply our style for this.
text width=\nameboxtempa,
Set the width to \nameboxtempa
to ensure it just accommodates the longest of the two lines it will contain.
]
#1
First names go here.
\tcblower
#2
Last name goes in the bottom part.
\end{tcolorbox}%
Close the environment and we're done with the left side of the big, outer box.
}{%
#3
The right side of that box gets whatever is in the third argument.
}
}

Complete code:
\documentclass{article}
\usepackage{tcolorbox,fontawesome}
\tcbuselibrary{xparse,skins}
\DeclareRobustCommand{\nameboxfont}{\normalfont\sffamily\bfseries\Large\baselineskip14pt}
\newlength\nameboxtempa
\newlength\nameboxtempb
\NewDocumentCommand \namebox { m m +m }{%
\settowidth\nameboxtempa{\nameboxfont #1}%
\settowidth\nameboxtempb{\nameboxfont #2}%
\ifdim\nameboxtempa<\nameboxtempb\setlength\nameboxtempa{\nameboxtempb}\fi%
\tcbsidebyside[two by two]{%
\begin{tcolorbox}[%
name box,
text width=\nameboxtempa,
]
#1
\tcblower
#2
\end{tcolorbox}%
}{%
#3
}
}
\tcbset{%
name box/.style={%
colback=black,
lower separated=false,
coltext=white,
fontupper=\nameboxfont,
fontlower=\nameboxfont,
halign=center,
halign lower=center,
sharpish corners,
middle=.75mm,
},
two by two/.style={%
sidebyside gap=1mm,
boxrule=0pt,
boxsep=0pt,
lower separated=false,
halign upper=left,
halign lower=left,
sidebyside adapt=left,
empty,
size=minimal,
},
}
\begin{document}
\namebox{First Names}{Last Name}{%
\begin{itemize}
\item[\faGithubSquare] github.com/Repository
\item[\faLinkedinSquare] linkedin.com/Account
\item[\faMobile] 0123 456789
\end{itemize}%
}
\namebox{Short Name}{Somewhat Longer Name}{%
\begin{itemize}
\item[\faGithubSquare] github.com/Repository
\item[\faLinkedinSquare] linkedin.com/Account
\item[\faMobile] 0123 456789
\end{itemize}%
}
\end{document}
\interlineskip
value. This can be switched of with\offlinterlineskip
, but do this in a group only]\parbox{4em} \hfill
the content of the\parbox
is _just`\hfill
jut need to put the content of the box inside{}