\usepackage{sectsty} 和 LaTeX 错误:命令 \sectionrule 已定义

\usepackage{sectsty} 和 LaTeX 错误:命令 \sectionrule 已定义

我是 LATEX 新手。我使用 latex 来创建简历,但在使用 \usepackage{sectsty} 和“moderncv”文档类时遇到错误:\

LaTeX 错误:命令 \sectionrule 已定义。LaTeX
错误:命令 \sectionfont 已定义。LaTeX
错误:命令 \subsectionfont 已定义。
包 sectsty 错误:sectsty 包不适用于\

以下是代码:

\documentclass[10pt,letterpaper,roman]{moderncv}       
\moderncvstyle{banking}                           
\moderncvcolor{blue}                                
\nopagenumbers{}                                 

% character encoding
\usepackage[utf8]{inputenc}
\usepackage{fontawesome}
\usepackage{fontspec}
\usepackage{tabularx}
\usepackage{ragged2e}
\usepackage{sectsty}
%\usepackage{CJKutf8}                              % if you need to use CJK to typeset your resume in Chinese, Japanese or Korean

% adjust the page margins
\usepackage[scale=0.8]{geometry}
    \geometry{letterpaper, top = 20mm, bottom = 20mm}
\usepackage{multicol}


\usepackage{import}
\renewcommand*{\namefont}{\fontsize{22}{40}\mdseries\upshape}
\renewcommand*{\subsectionfont}{\fontsize{10}{20}\mdseries\upshape}

知道如何修复此问题吗?我试图缩小子部分和名称的字体大小。

答案1

moderncv与包不兼容sectsty。你可以在文件中产生的错误消息中看到这一点.log

! Package sectsty Error: The sectsty package doesn't work with
(sectsty)                this document class.

See the sectsty package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.296     scrartcl, scrbook, and scrreprt.}
                                           
The sectsty package only works with the following classes: 
the standard LaTeX document classes
article, report, and book; and
the KOMA-Script classes
scrartcl, scrbook, and scrreprt.

在评论了调用sectsty并纠正了一些其他错误(参见<======以下 MWE 中的标记)并添加缺失的部分以获得可编译的代码后:

\documentclass[10pt,letterpaper,roman]{moderncv}
\moderncvstyle{banking}
\moderncvcolor{blue}
\nopagenumbers{}

% character encoding
\usepackage[utf8]{inputenc}
\usepackage{fontawesome}
%\usepackage{fontspec} % <===================== use inputenc or fontspec
\usepackage{tabularx}
\usepackage{ragged2e}
%\usepackage{sectsty} % <================== not compatible with moderncv

% adjust the page margins
\usepackage[scale=0.8]{geometry}
    \geometry{letterpaper, top = 20mm, bottom = 20mm}
\usepackage{multicol}


%\usepackage{import} % <============================================ ???
\renewcommand*{\namefont}{\fontsize{22}{40}\mdseries\upshape}
\renewcommand*{\subsectionfont}{\fontsize{10}{20}\mdseries\upshape}

% <======================================================== missing part
% personal data
\name{John}{Doe}
\title{Resumé title}
\address{street and number}{postcode city}{country}
\phone[mobile]{+1~(234)~567~890}
\phone[fixed]{+2~(345)~678~901}
\phone[fax]{+3~(456)~789~012}
\email{[email protected]}
\homepage{www.johndoe.com}
\social[linkedin]{john.doe}
\social[twitter]{jdoe}
\social[github]{jdoe}
\extrainfo{additional information}
\photo[64pt][0.4pt]{example-image-golden-upright}%
\quote{Some quote}


\begin{document}

\makecvtitle

\section{Education}
\cventry{year--year}{Degree}{Institution--3}{City--4}{\textit{Grade}--5}{Description--6}  % arguments 3 to 6 can be left empty
\cventry{year--year}{Degree}{Institution}{City}{\textit{Grade}}{Description}

\end{document}

您可以顺利进行编译并得到以下结果:

生成的 pdf

相关内容