如何解决LaTeX简历中轮状图文字重叠、错位及溢出问题?
LaTeX简历轮状图排版问题解决
问题描述
作为LaTeX新手,制作简历时使用轮状图展示技能,遇到以下三个排版问题:
- 文字与图形重叠
- 图形未居中显示
- 文字溢出至页面右侧区域
相关代码
.tex 文件代码
\profilesection{Hard Skills} \wheelchart{3.7em}{2em}{% 20/3em/yellow!75/\mbox{Object Oriented Programming}, 30/4em/Opal!40/C\#, 30/3em/blue!75/.NET Core, 30/3em/orange!75/\mbox{Software Engineering} }
.cls 文件代码
\newcommand{\wheelchart}[4][-90]{% \def\outerradius{#2}% \def\innerradius{#3}% % Calculate total \pgfmathsetmacro{\totalnum}{0}% \foreach\value/\colour/\name in {#4} {% \pgfmathparse{\value+\totalnum}% \global\let\totalnum=\pgfmathresult% }% \begin{tikzpicture} % Calculate the thickness and the middle line of the wheel \pgfmathsetmacro{\wheelwidth}{\outerradius-\innerradius} \pgfmathsetmacro{\midradius}{(\outerradius+\innerradius)/2} % Rotate so we start from the top \begin{scope}[rotate=#1, on background layer] % Loop through each value set. \cumnum keeps track of where we are in the % wheel \pgfmathsetmacro{\cumnum}{0} \foreach \value/\width/\colour/\name in {#4} { \pgfmathsetmacro{\newcumnum}{\cumnum + \value/\totalnum*360} % Calculate the percent value \pgfmathsetmacro{\percentage}{\value/\totalnum*100} % Calculate the mid angle of the colour segments to place the labels \pgfmathsetmacro{\midangle}{-(\cumnum+\newcumnum)/2} % This is necessary for the labels to align nicely \pgfmathparse{ (-\midangle>180?"west":"east") } \edef\textanchor{\pgfmathresult} \pgfmathparse{ (-\midangle>180?"flush left":"flush right") } \edef\textalign{\pgfmathresult} \pgfmathsetmacro\labelshiftdir{1-2*(-\midangle<180)} % Draw the color segments. Somehow, the \midrow units got lost, so % we add 'pt' at the end. Not nice... \filldraw[draw=white,fill=\colour] (-\cumnum:\outerradius) arc (-\cumnum:-\newcumnum:\outerradius) -- (-\newcumnum:\innerradius) arc (-\newcumnum:-\cumnum:\innerradius) -- cycle; % Draw the data labels \draw [*-,thin,wheelchartlabelcolor] node [append after command={ (\midangle:\midradius pt) -- (\midangle:\outerradius + 1ex) -- (\tikzlastnode)}] at (\midangle:\outerradius + 1ex) [ xshift=\labelshiftdir*0.5cm,inner sep=1ex, outer sep=0pt, text width=\width, anchor=\textanchor, align=\textalign, font=\small, text=wheeltextcolor ]{\name}; % Set the old cumulated angle to the new value \global\let\cumnum=\newcumnum } \end{scope} \end{tikzpicture}\par
当前效果
轮状图存在文字与图形重叠、整体未居中、右侧文字溢出页面的问题。
解决方案
1. 修复图形未居中问题
将tikzpicture环境包裹在center环境中,确保图形整体居中:
% 修改.cls文件中的tikzpicture部分 \begin{center} \begin{tikzpicture} % 原tikz代码保持不变 \end{tikzpicture} \end{center}
2. 解决文字重叠与溢出问题
调整标签位置与间距
修改.cls文件中标签的xshift和inner sep参数,减少标签与图形的偏移量,避免重叠:
% 替换原标签绘制代码 \draw [*-,thin,wheelchartlabelcolor] node [append after command={ (\midangle:\midradius pt) -- (\midangle:\outerradius + 1.5ex) -- (\tikzlastnode)}] at (\midangle:\outerradius + 1.5ex) [ xshift=\labelshiftdir*0.2cm,inner sep=0.5ex, outer sep=0pt, text width=\width, anchor=\textanchor, align=\textalign, font=\small, text=wheeltextcolor ]{\name};
优化文本宽度与轮状图尺寸
在.tex调用中,根据文字长度调整text width(给长文本分配更宽的空间),同时适当缩小轮状图半径,给外侧标签留出更多页面空间:
\profilesection{Hard Skills} \wheelchart{3em}{1.8em}{% 20/5em/yellow!75/\mbox{Object Oriented Programming}, 30/4em/Opal!40/C\#, 30/3em/blue!75/.NET Core, 30/4em/orange!75/\mbox{Software Engineering} }
内容的提问来源于stack exchange,提问作者Keerthi Nandigam
相关产品推荐
相关产品推荐

