# Photo option in .sty file for LaTeX CV

I have a .sty file for my CV which create a box at the beginning where I could give my name (first column) and my info (2nd column). I want to include my photo (.jpg/.gif) to the right of my info (as third column). The relevant lines of .sty file looks like this:

Here is the working example: .sty file

\usepackage{paralist,datetime}
\usepackage{hyperref,fancyhdr,enumitem,color}
\usepackage[a4paper,text={17.5cm,25.5cm},centering]{geometry}
\usepackage[compact,small,sf,bf]{titlesec}
\usepackage{kpfonts,dsfont}

\sloppy

\pagestyle{fancy}
\lhead{\sf ccc: \@name}
\rhead{\sf\thepage}
\cfoot{}

\def\name#1{\def\@name{#1}}
\def\info#1{\def\@info{#1}}
\newcommand{\shadebox}[3][.9]{\fcolorbox[gray]{0}{#1}{\parbox{#2}{#3}}}

\def\maketitle{
\thispagestyle{plain}
\vspace*{-1.4cm}
\shadebox[0.9]{17.3cm}{\sf\color[rgb]{.6,0,0}
\hbox to 17cm{\begin{tabular}{p{7.4cm}}
\LARGE\textbf{\@name}\\[0.3cm]
\Large\textbf{Curriculum Vitae}\\[0.6cm]
\normalsize\today
\end{tabular}
\hfill\hbox{\fontsize{9}{12}\sf
\begin{tabular}{@{}rp{7.2cm}@{}}
\@info
\end{tabular}}}
}
\vspace*{0.2cm}}

\titlelabel{}
\titlespacing{\section}{0pt}{2ex}{1ex}
\titleformat*{\section}{\color[rgb]{0.6,0,0}\large\sf\bfseries}
\titlespacing{\subsection}{0pt}{1ex}{0.5ex}

\setlength{\parskip}{0ex}
\setlength{\parindent}{0em}
\setlength{\headheight}{15pt}
\setlength{\tabcolsep}{0.15cm}
\clubpenalty = 10000
\widowpenalty = 10000
\setlist{itemsep=1pt}
\setdescription{labelwidth=1.2cm,leftmargin=1.5cm,labelindent=1.5cm,font=\rm}


And my mwe.tex file looks like this:

\documentclass[a4paper,11pt]{article}
\usepackage{/Users/sushilchauhan/cv/cv}
\usepackage{setspace}
\usepackage{multicol}
\usepackage{url}
\usepackage{hyperref}
\usepackage{color,soul}
\usepackage{longtable}
\definecolor{lightgray}{gray}{0.85}
\sethlcolor{lightgray}
\def\met{\mbox{${\hbox{$E$\kern-0.45em\lower-.1ex\hbox{\bf{/}}}}_T$}~}

\name{Dr. XYZ}
\info{Address: & XYZ\\
phone: & XYZ}

\begin{document}

\vspace{25pt}
\maketitle

\end{document}


So I simply give my name and info like this:

\name{XYZ}
\info{Address: XYZ}


I would like to ask how I could add the photo also along with \name and \info.

• Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem.
– DG'
Jan 2 '18 at 20:34
• Did my answer helped you? If yes please consider to accept it. That is the way here to say "Thank you for your help"! After you have earned rep 15 or more you are able to upvote too ... Jun 6 '19 at 17:37

## 1 Answer

I copied your cv.sty file into your mwe.tex file to get only one file to be compiled. Of course you can use your original files. Please see the important changed code marked in the following mwe with <===========.

I added the definition

\newcommand*{\photo}[2]{\def\@photowidth{#1}\def\@photoname{#2}} % <====


for a new command \photo

\photo{3cm}{example-image} % <==========================================


with the width to be used and the file name for command \includegraphics.

Then you need to add a new minipage to your table in your command \maketitle:

\begin{minipage}[c]{\@photowidth} % <=================================
\includegraphics[width=\@photowidth]{\@photoname}% <================
\end{minipage} % <====================================================


With the following complete mwe

\documentclass[a4paper,11pt]{article}

% content of cv.sty
\makeatletter % <=======================================================
\usepackage{paralist,datetime}
\usepackage{fancyhdr,enumitem,color}
\usepackage[a4paper,text={17.5cm,25.5cm},centering]{geometry}
\usepackage[compact,small,sf,bf]{titlesec}
\usepackage{kpfonts,dsfont}
\usepackage{graphicx}

\sloppy

\pagestyle{fancy}
\lhead{\sf ccc: \@name}
\rhead{\sf\thepage}
\cfoot{}

\def\name#1{\def\@name{#1}}
\def\info#1{\def\@info{#1}}
\newcommand{\shadebox}[3][.9]{\fcolorbox[gray]{0}{#1}{\parbox{#2}{#3}}}
% Usage: \photo{3cm}{example-image} % width name
\newcommand*{\photo}[2]{\def\@photowidth{#1}\def\@photoname{#2}} % <====

\def\maketitle{
\thispagestyle{plain}
\vspace*{-1.4cm}
\shadebox[0.9]{17.3cm}{\sf\color[rgb]{.6,0,0}
\hbox to 17cm{%
\begin{tabular}{p{5.4cm}}
\LARGE\textbf{\@name}\\[0.3cm]
\Large\textbf{Curriculum Vitae}\\[0.6cm]
\normalsize\today
\end{tabular}
\hfill\hbox{\fontsize{9}{12}\sf
\begin{tabular}{@{}rp{6.2cm}@{}}
\@info
\end{tabular}}\hfill
\begin{minipage}[c]{\@photowidth} % <=================================
\includegraphics[width=\@photowidth]{\@photoname}% <================
\end{minipage} % <====================================================
}
}
\vspace*{0.2cm}}

\titlelabel{}
\titlespacing{\section}{0pt}{2ex}{1ex}
\titleformat*{\section}{\color[rgb]{0.6,0,0}\large\sf\bfseries}
\titlespacing{\subsection}{0pt}{1ex}{0.5ex}

\setlength{\parskip}{0ex}
\setlength{\parindent}{0em}
\setlength{\headheight}{15pt}
\setlength{\tabcolsep}{0.15cm}
\clubpenalty = 10000
\widowpenalty = 10000
\setlist{itemsep=1pt}
\setdescription{labelwidth=1.2cm,leftmargin=1.5cm,labelindent=1.5cm,font=\rm}
\makeatother % <========================================================

\usepackage{setspace}
\usepackage{multicol}
\usepackage{url}

\usepackage{color,soul}
\usepackage{longtable}

\usepackage{hyperref}

\definecolor{lightgray}{gray}{0.85}
\sethlcolor{lightgray}
\def\met{\mbox{${\hbox{$E$\kern-0.45em\lower-.1ex\hbox{\bf{/}}}}_T$}~}

\name{Dr. XYZ}
\info{Address: & XYZ\\
phone: & XYZ}
\photo{3cm}{example-image} % <==========================================

\begin{document}

\vspace{25pt}
\maketitle

\end{document}


you get the wished result:

Please see that \makeatletter and \makeatother are only needed because you used @ in your file cv.sty ...