Draw a line with an icon in the middle

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
5
down vote

favorite
1












I'm new to LaTeX and I'm writing my resume using ModernCV and a lot of googling.



I use the classic style and wish to make the document look a little more visual by adding icons to the section titles. For now I plan to use FontAwesome icons.



So far, I redefined the section command to include a third argument (the icon/character to use).



documentclass[a4paper, 11pt, color, final, roman]moderncv
usepackage[scale=0.9]geometry
AtBeginDocumentrecomputelengths
usepackagefontspec

moderncvstyleclassic
moderncviconsawesome
sethintscolumnlength3cm

RenewDocumentCommandsectionsmm % third argument is [m]andatory
paraddvspace2.5ex
phantomsection
addcontentslinetocsection#2
cvitem[0ex]
colorcolor1 % Use the CV color
% Left line
strutraggedleftraiseboxbaseletterheight
rulehintscolumnwidth - 2cm0.3ex
% The icon
fontsize.5cm0cm#3
% Right line
strutraggedleftraiseboxbaseletterheight
rulehintscolumnwidth - 2cm0.3ex

strutsectionstyle#2 % Section title


firstnamegnxr
lastnamedemo

begindocument

sectionCompétencesfaWrench
closesection

enddocument


The output so far is:



A wrench icon next to the section title



It looks kinda good. However, I feel like it is a hacky solution. I have no idea of the real width of the icon so all measures (2cm, .5cm) are the result of trial and error for this specific icon. The results for other characters are just wrong:



A section with the letter "m" as an icon, followed by a section with the letter "i" as an icon. We can see lines are not the same width.



Also there is a small undesired space inserted between the lines and the icon (we can notice for example that the space between the icon and the right line is bigger than with the left line).



I think a good solution would be to draw a single line instead of two, then draw the icon at the (computed) center of the line with a (fixed-width) white background. Is this the good approach? How can I do that?










share|improve this question



















  • 1




    @MarcelKrüger Thanks :) It should now be compilable (I use xelatex to process the file)
    – GnxR
    Aug 11 at 11:01






  • 1




    +1 just for moderncv (and a bit for the French). My documents with accented characters, compiled with pdflatex, require a slightly longer preamble.
    – phollox
    Aug 11 at 12:18











  • @phollox I use usepackage[francais]babel and I'm not sure but I think the reason I use xelatex instead of pdflatex is because the former expects utf-8 by default while the latter requires a declaration
    – GnxR
    Aug 11 at 13:45











  • Indeed. There are several lines required to set your document. I struggled a lot with that in my first LaTeX document. For some reason, the school template was saved in Latin1 encoding, not UTF-8, and there were even more lines to make it work in pdflatex
    – phollox
    Aug 13 at 1:08














up vote
5
down vote

favorite
1












I'm new to LaTeX and I'm writing my resume using ModernCV and a lot of googling.



I use the classic style and wish to make the document look a little more visual by adding icons to the section titles. For now I plan to use FontAwesome icons.



So far, I redefined the section command to include a third argument (the icon/character to use).



documentclass[a4paper, 11pt, color, final, roman]moderncv
usepackage[scale=0.9]geometry
AtBeginDocumentrecomputelengths
usepackagefontspec

moderncvstyleclassic
moderncviconsawesome
sethintscolumnlength3cm

RenewDocumentCommandsectionsmm % third argument is [m]andatory
paraddvspace2.5ex
phantomsection
addcontentslinetocsection#2
cvitem[0ex]
colorcolor1 % Use the CV color
% Left line
strutraggedleftraiseboxbaseletterheight
rulehintscolumnwidth - 2cm0.3ex
% The icon
fontsize.5cm0cm#3
% Right line
strutraggedleftraiseboxbaseletterheight
rulehintscolumnwidth - 2cm0.3ex

strutsectionstyle#2 % Section title


firstnamegnxr
lastnamedemo

begindocument

sectionCompétencesfaWrench
closesection

enddocument


The output so far is:



A wrench icon next to the section title



It looks kinda good. However, I feel like it is a hacky solution. I have no idea of the real width of the icon so all measures (2cm, .5cm) are the result of trial and error for this specific icon. The results for other characters are just wrong:



A section with the letter "m" as an icon, followed by a section with the letter "i" as an icon. We can see lines are not the same width.



Also there is a small undesired space inserted between the lines and the icon (we can notice for example that the space between the icon and the right line is bigger than with the left line).



I think a good solution would be to draw a single line instead of two, then draw the icon at the (computed) center of the line with a (fixed-width) white background. Is this the good approach? How can I do that?










share|improve this question



















  • 1




    @MarcelKrüger Thanks :) It should now be compilable (I use xelatex to process the file)
    – GnxR
    Aug 11 at 11:01






  • 1




    +1 just for moderncv (and a bit for the French). My documents with accented characters, compiled with pdflatex, require a slightly longer preamble.
    – phollox
    Aug 11 at 12:18











  • @phollox I use usepackage[francais]babel and I'm not sure but I think the reason I use xelatex instead of pdflatex is because the former expects utf-8 by default while the latter requires a declaration
    – GnxR
    Aug 11 at 13:45











  • Indeed. There are several lines required to set your document. I struggled a lot with that in my first LaTeX document. For some reason, the school template was saved in Latin1 encoding, not UTF-8, and there were even more lines to make it work in pdflatex
    – phollox
    Aug 13 at 1:08












up vote
5
down vote

favorite
1









up vote
5
down vote

favorite
1






1





I'm new to LaTeX and I'm writing my resume using ModernCV and a lot of googling.



I use the classic style and wish to make the document look a little more visual by adding icons to the section titles. For now I plan to use FontAwesome icons.



So far, I redefined the section command to include a third argument (the icon/character to use).



documentclass[a4paper, 11pt, color, final, roman]moderncv
usepackage[scale=0.9]geometry
AtBeginDocumentrecomputelengths
usepackagefontspec

moderncvstyleclassic
moderncviconsawesome
sethintscolumnlength3cm

RenewDocumentCommandsectionsmm % third argument is [m]andatory
paraddvspace2.5ex
phantomsection
addcontentslinetocsection#2
cvitem[0ex]
colorcolor1 % Use the CV color
% Left line
strutraggedleftraiseboxbaseletterheight
rulehintscolumnwidth - 2cm0.3ex
% The icon
fontsize.5cm0cm#3
% Right line
strutraggedleftraiseboxbaseletterheight
rulehintscolumnwidth - 2cm0.3ex

strutsectionstyle#2 % Section title


firstnamegnxr
lastnamedemo

begindocument

sectionCompétencesfaWrench
closesection

enddocument


The output so far is:



A wrench icon next to the section title



It looks kinda good. However, I feel like it is a hacky solution. I have no idea of the real width of the icon so all measures (2cm, .5cm) are the result of trial and error for this specific icon. The results for other characters are just wrong:



A section with the letter "m" as an icon, followed by a section with the letter "i" as an icon. We can see lines are not the same width.



Also there is a small undesired space inserted between the lines and the icon (we can notice for example that the space between the icon and the right line is bigger than with the left line).



I think a good solution would be to draw a single line instead of two, then draw the icon at the (computed) center of the line with a (fixed-width) white background. Is this the good approach? How can I do that?










share|improve this question















I'm new to LaTeX and I'm writing my resume using ModernCV and a lot of googling.



I use the classic style and wish to make the document look a little more visual by adding icons to the section titles. For now I plan to use FontAwesome icons.



So far, I redefined the section command to include a third argument (the icon/character to use).



documentclass[a4paper, 11pt, color, final, roman]moderncv
usepackage[scale=0.9]geometry
AtBeginDocumentrecomputelengths
usepackagefontspec

moderncvstyleclassic
moderncviconsawesome
sethintscolumnlength3cm

RenewDocumentCommandsectionsmm % third argument is [m]andatory
paraddvspace2.5ex
phantomsection
addcontentslinetocsection#2
cvitem[0ex]
colorcolor1 % Use the CV color
% Left line
strutraggedleftraiseboxbaseletterheight
rulehintscolumnwidth - 2cm0.3ex
% The icon
fontsize.5cm0cm#3
% Right line
strutraggedleftraiseboxbaseletterheight
rulehintscolumnwidth - 2cm0.3ex

strutsectionstyle#2 % Section title


firstnamegnxr
lastnamedemo

begindocument

sectionCompétencesfaWrench
closesection

enddocument


The output so far is:



A wrench icon next to the section title



It looks kinda good. However, I feel like it is a hacky solution. I have no idea of the real width of the icon so all measures (2cm, .5cm) are the result of trial and error for this specific icon. The results for other characters are just wrong:



A section with the letter "m" as an icon, followed by a section with the letter "i" as an icon. We can see lines are not the same width.



Also there is a small undesired space inserted between the lines and the icon (we can notice for example that the space between the icon and the right line is bigger than with the left line).



I think a good solution would be to draw a single line instead of two, then draw the icon at the (computed) center of the line with a (fixed-width) white background. Is this the good approach? How can I do that?







moderncv






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 11 at 13:59

























asked Aug 11 at 10:23









GnxR

1286




1286







  • 1




    @MarcelKrüger Thanks :) It should now be compilable (I use xelatex to process the file)
    – GnxR
    Aug 11 at 11:01






  • 1




    +1 just for moderncv (and a bit for the French). My documents with accented characters, compiled with pdflatex, require a slightly longer preamble.
    – phollox
    Aug 11 at 12:18











  • @phollox I use usepackage[francais]babel and I'm not sure but I think the reason I use xelatex instead of pdflatex is because the former expects utf-8 by default while the latter requires a declaration
    – GnxR
    Aug 11 at 13:45











  • Indeed. There are several lines required to set your document. I struggled a lot with that in my first LaTeX document. For some reason, the school template was saved in Latin1 encoding, not UTF-8, and there were even more lines to make it work in pdflatex
    – phollox
    Aug 13 at 1:08












  • 1




    @MarcelKrüger Thanks :) It should now be compilable (I use xelatex to process the file)
    – GnxR
    Aug 11 at 11:01






  • 1




    +1 just for moderncv (and a bit for the French). My documents with accented characters, compiled with pdflatex, require a slightly longer preamble.
    – phollox
    Aug 11 at 12:18











  • @phollox I use usepackage[francais]babel and I'm not sure but I think the reason I use xelatex instead of pdflatex is because the former expects utf-8 by default while the latter requires a declaration
    – GnxR
    Aug 11 at 13:45











  • Indeed. There are several lines required to set your document. I struggled a lot with that in my first LaTeX document. For some reason, the school template was saved in Latin1 encoding, not UTF-8, and there were even more lines to make it work in pdflatex
    – phollox
    Aug 13 at 1:08







1




1




@MarcelKrüger Thanks :) It should now be compilable (I use xelatex to process the file)
– GnxR
Aug 11 at 11:01




@MarcelKrüger Thanks :) It should now be compilable (I use xelatex to process the file)
– GnxR
Aug 11 at 11:01




1




1




+1 just for moderncv (and a bit for the French). My documents with accented characters, compiled with pdflatex, require a slightly longer preamble.
– phollox
Aug 11 at 12:18





+1 just for moderncv (and a bit for the French). My documents with accented characters, compiled with pdflatex, require a slightly longer preamble.
– phollox
Aug 11 at 12:18













@phollox I use usepackage[francais]babel and I'm not sure but I think the reason I use xelatex instead of pdflatex is because the former expects utf-8 by default while the latter requires a declaration
– GnxR
Aug 11 at 13:45





@phollox I use usepackage[francais]babel and I'm not sure but I think the reason I use xelatex instead of pdflatex is because the former expects utf-8 by default while the latter requires a declaration
– GnxR
Aug 11 at 13:45













Indeed. There are several lines required to set your document. I struggled a lot with that in my first LaTeX document. For some reason, the school template was saved in Latin1 encoding, not UTF-8, and there were even more lines to make it work in pdflatex
– phollox
Aug 13 at 1:08




Indeed. There are several lines required to set your document. I struggled a lot with that in my first LaTeX document. For some reason, the school template was saved in Latin1 encoding, not UTF-8, and there were even more lines to make it work in pdflatex
– phollox
Aug 13 at 1:08










1 Answer
1






active

oldest

votes

















up vote
3
down vote



accepted










You can use a hbox to fix a specific width, then use leaders to fill the box on both sides with a line until the specified width is reached:



documentclass[a4paper, 11pt, color, final, roman]moderncv
usepackage[scale=0.9]geometry
AtBeginDocumentrecomputelengths
usepackagefontspec

moderncvstyleclassic
moderncviconsawesome
sethintscolumnlength3cm

RenewDocumentCommandsectionsmm% third argument is [m]andatory
paraddvspace2.5ex%
phantomsection%
addcontentslinetocsection#2%
cvitem[0ex]%
struthbox to hintscolumnwidth%
colorcolor1%
fontsize.5cm0cmselectfont
leadershrule width-baseletterheight heightdimexprbaseletterheight+0.3exrelaxhfill
space #3
leadershrule width-baseletterheight heightdimexprbaseletterheight+0.3exrelaxhfill
%
%
strutsectionstyle#2% Section title


firstnamegnxr
lastnamedemo

begindocument

sectionCompétencesfaWrench
closesection

enddocument


You might notice that a lot of lines are ended with %. Without this TeX inserts a space there which destroys the symmetrie.






share|improve this answer




















  • Awesome, thanks! I replaced the hrules with leadershrule width-0pt depth-3pt height 5pthfill (negative depth to control vertical positioning). For some reason positioning with raisebox didn't work.
    – GnxR
    Aug 11 at 13:37










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "85"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f445623%2fdraw-a-line-with-an-icon-in-the-middle%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
3
down vote



accepted










You can use a hbox to fix a specific width, then use leaders to fill the box on both sides with a line until the specified width is reached:



documentclass[a4paper, 11pt, color, final, roman]moderncv
usepackage[scale=0.9]geometry
AtBeginDocumentrecomputelengths
usepackagefontspec

moderncvstyleclassic
moderncviconsawesome
sethintscolumnlength3cm

RenewDocumentCommandsectionsmm% third argument is [m]andatory
paraddvspace2.5ex%
phantomsection%
addcontentslinetocsection#2%
cvitem[0ex]%
struthbox to hintscolumnwidth%
colorcolor1%
fontsize.5cm0cmselectfont
leadershrule width-baseletterheight heightdimexprbaseletterheight+0.3exrelaxhfill
space #3
leadershrule width-baseletterheight heightdimexprbaseletterheight+0.3exrelaxhfill
%
%
strutsectionstyle#2% Section title


firstnamegnxr
lastnamedemo

begindocument

sectionCompétencesfaWrench
closesection

enddocument


You might notice that a lot of lines are ended with %. Without this TeX inserts a space there which destroys the symmetrie.






share|improve this answer




















  • Awesome, thanks! I replaced the hrules with leadershrule width-0pt depth-3pt height 5pthfill (negative depth to control vertical positioning). For some reason positioning with raisebox didn't work.
    – GnxR
    Aug 11 at 13:37














up vote
3
down vote



accepted










You can use a hbox to fix a specific width, then use leaders to fill the box on both sides with a line until the specified width is reached:



documentclass[a4paper, 11pt, color, final, roman]moderncv
usepackage[scale=0.9]geometry
AtBeginDocumentrecomputelengths
usepackagefontspec

moderncvstyleclassic
moderncviconsawesome
sethintscolumnlength3cm

RenewDocumentCommandsectionsmm% third argument is [m]andatory
paraddvspace2.5ex%
phantomsection%
addcontentslinetocsection#2%
cvitem[0ex]%
struthbox to hintscolumnwidth%
colorcolor1%
fontsize.5cm0cmselectfont
leadershrule width-baseletterheight heightdimexprbaseletterheight+0.3exrelaxhfill
space #3
leadershrule width-baseletterheight heightdimexprbaseletterheight+0.3exrelaxhfill
%
%
strutsectionstyle#2% Section title


firstnamegnxr
lastnamedemo

begindocument

sectionCompétencesfaWrench
closesection

enddocument


You might notice that a lot of lines are ended with %. Without this TeX inserts a space there which destroys the symmetrie.






share|improve this answer




















  • Awesome, thanks! I replaced the hrules with leadershrule width-0pt depth-3pt height 5pthfill (negative depth to control vertical positioning). For some reason positioning with raisebox didn't work.
    – GnxR
    Aug 11 at 13:37












up vote
3
down vote



accepted







up vote
3
down vote



accepted






You can use a hbox to fix a specific width, then use leaders to fill the box on both sides with a line until the specified width is reached:



documentclass[a4paper, 11pt, color, final, roman]moderncv
usepackage[scale=0.9]geometry
AtBeginDocumentrecomputelengths
usepackagefontspec

moderncvstyleclassic
moderncviconsawesome
sethintscolumnlength3cm

RenewDocumentCommandsectionsmm% third argument is [m]andatory
paraddvspace2.5ex%
phantomsection%
addcontentslinetocsection#2%
cvitem[0ex]%
struthbox to hintscolumnwidth%
colorcolor1%
fontsize.5cm0cmselectfont
leadershrule width-baseletterheight heightdimexprbaseletterheight+0.3exrelaxhfill
space #3
leadershrule width-baseletterheight heightdimexprbaseletterheight+0.3exrelaxhfill
%
%
strutsectionstyle#2% Section title


firstnamegnxr
lastnamedemo

begindocument

sectionCompétencesfaWrench
closesection

enddocument


You might notice that a lot of lines are ended with %. Without this TeX inserts a space there which destroys the symmetrie.






share|improve this answer












You can use a hbox to fix a specific width, then use leaders to fill the box on both sides with a line until the specified width is reached:



documentclass[a4paper, 11pt, color, final, roman]moderncv
usepackage[scale=0.9]geometry
AtBeginDocumentrecomputelengths
usepackagefontspec

moderncvstyleclassic
moderncviconsawesome
sethintscolumnlength3cm

RenewDocumentCommandsectionsmm% third argument is [m]andatory
paraddvspace2.5ex%
phantomsection%
addcontentslinetocsection#2%
cvitem[0ex]%
struthbox to hintscolumnwidth%
colorcolor1%
fontsize.5cm0cmselectfont
leadershrule width-baseletterheight heightdimexprbaseletterheight+0.3exrelaxhfill
space #3
leadershrule width-baseletterheight heightdimexprbaseletterheight+0.3exrelaxhfill
%
%
strutsectionstyle#2% Section title


firstnamegnxr
lastnamedemo

begindocument

sectionCompétencesfaWrench
closesection

enddocument


You might notice that a lot of lines are ended with %. Without this TeX inserts a space there which destroys the symmetrie.







share|improve this answer












share|improve this answer



share|improve this answer










answered Aug 11 at 11:26









Marcel Krüger

10.4k11032




10.4k11032











  • Awesome, thanks! I replaced the hrules with leadershrule width-0pt depth-3pt height 5pthfill (negative depth to control vertical positioning). For some reason positioning with raisebox didn't work.
    – GnxR
    Aug 11 at 13:37
















  • Awesome, thanks! I replaced the hrules with leadershrule width-0pt depth-3pt height 5pthfill (negative depth to control vertical positioning). For some reason positioning with raisebox didn't work.
    – GnxR
    Aug 11 at 13:37















Awesome, thanks! I replaced the hrules with leadershrule width-0pt depth-3pt height 5pthfill (negative depth to control vertical positioning). For some reason positioning with raisebox didn't work.
– GnxR
Aug 11 at 13:37




Awesome, thanks! I replaced the hrules with leadershrule width-0pt depth-3pt height 5pthfill (negative depth to control vertical positioning). For some reason positioning with raisebox didn't work.
– GnxR
Aug 11 at 13:37

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f445623%2fdraw-a-line-with-an-icon-in-the-middle%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?