字体更改不起作用

字体更改不起作用

正如标题所说,我想用例如更改文档的字体

\usepackage[T1]{fontenc}
\newcommand{\changefont}[3]{
\fontfamily{#1} \fontseries{#2} \fontshape{#3} \selectfont}
\changefont{phv}{b}{sl}

但它不起作用。没有任何变化。字体保持不变。我已经尝试了不同的字体。

这是我的代码:

\documentclass{book}
\usepackage{geometry}
\geometry{left=4cm,right=3cm, top=2cm, bottom=2cm} 
\usepackage[pagestyles]{titlesec}
\titlespacing*{\chapter}{0pt}{-30pt}{20pt}
\titleformat{\chapter}[display]{\color{headercolor}\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}{20pt}{\Huge}

\titleformat{\section}
{\color{headercolor}\normalfont\Large\bfseries}{\thesection}{1em}{}

\titleformat{\subsection}
{\color{headercolor}\normalfont\Large\bfseries}{\thesubsection}{1em}{}

\titleformat{\subsubsection}
{\color{headercolor}\normalfont\large\bfseries}{\thesubsubsection}{1em}{}

\titleformat{\paragraph}
{\color{headercolor}\normalfont\normalsize\bfseries}{\theparagraph}{1em}{}

\usepackage[T1]{fontenc}
\newcommand{\changefont}[3]{
\fontfamily{#1} \fontseries{#2} \fontshape{#3} \selectfont}
\changefont{phv}{b}{sl}

\usepackage[ngerman]{babel}
\usepackage{mathptmx}
\usepackage{helvet}
\usepackage{wallpaper}
\usepackage{color}
\usepackage[final]{pdfpages} 
%,bookmarksopenlevel={1}
%\usepackage[hidelinks,bookmarks=true,bookmarksopen=true,bookmarksnumbered=true,colorlinks=true,linkcolor=black,]{hyperref}
\usepackage[hidelinks,bookmarksopen=false,
hypertexnames=TRUE,pdfpagelabels=true]{hyperref}[2011/02/05]%colorlinks,linkcolor=black,
\hypersetup{ 
  pdftitle={},
%  pdfauthor={},
  pdfsubject={satistics book}, 
  pdfkeywords={}, 
  }

\usepackage{xcolor,bookmark}
\usepackage{scrextend}
\usepackage{titlepic}
\usepackage{shorttoc}
\usepackage{courier}
\usepackage{type1cm}         
\usepackage{zref-abspage}
\usepackage{makeidx}        
\usepackage{graphicx}        
\usepackage{multicol}        
\usepackage[bottom]{footmisc}
\usepackage{tocstyle}
\usetocstyle{allwithdot} 
%\usepackage{thmbox}
\usepackage{shadethm}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{marginnote}
%\usetocstyle{KOMAlike}
\usepackage{wrapfig}
\usepackage{paralist}
\usepackage{amssymb}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{ulem}
\usepackage{fancyhdr}
%\usepackage{sectsty}
\usepackage{booktabs}
\makeindex           
\listfiles

\newmdenv[backgroundcolor=textbeispiel,linecolor=blue,roundcorner=10pt,outerlinewidth=1pt,skipbelow=2pt, skipabove=6pt]{myframedenv}%innerlinecolor=green,innerlinewidth=1pt,middlelinewidth=2pt,middlelinecolor=yellow

\newtheoremstyle{mystyle}
  {}{}{}{}%
  {\bfseries}{:}{.5em}{}%

\newtheoremstyle{mystyle2}
  {}{}{}{}%
  {\bfseries}{}{.5em}{}%

\theoremstyle{mystyle}

\newmdtheoremenv[hidealllines=true,backgroundcolor=shadethmcolor,skipabove=\topsep,
skipbelow=\topsep]{beispiel}{Beispiel}

\newmdtheoremenv[hidealllines=true,
backgroundcolor=shadethmcolor2,skipabove=0pt,
skipbelow=0pt]{formel}{Formel}


\theoremstyle{mystyle2}

\newmdtheoremenv[hidealllines=true,
backgroundcolor=aufgaben,skipabove=0pt,
skipbelow=0pt]{aufgabe}{Aufgabe}


\newmdtheoremenv[hidealllines=true,
backgroundcolor=loesung,skipabove=0pt,
skipbelow=0pt]{loesung}{L\"osung}

\definecolor{dunkelgruen}{rgb}{0.8,0.87843,0.8}
\definecolor{hellgruen}{rgb}{0.90196,0.941176,0.90196}
\definecolor{aufgaben}{rgb}{0.9333,0.93333,0.933333}
\definecolor{headercolor}{rgb}{0.6941,0.6745,0.4863}

\newpagestyle{mystyle}{
\headrule \sethead[\thepage][][\color{red} \chaptertitlename\ \thechapter. \chaptertitle]
{\color{red} \thesection\ \sectiontitle}{}{\thepage}}

\setlength{\headheight}{24pt}%

\begin{document}
\frontmatter

\setlength{\marginparwidth}{3cm}
\marginparsep = 0.4cm
\pagestyle{plain}
\pagenumbering{Roman}

\makeatletter
\let\stdl@part\l@part
\renewcommand*{\l@part}[2]{%
  \stdl@part{\textcolor{headercolor}{#1}}{\textcolor{headercolor}{#2}}}
\let\stdl@chapter\l@chapter
\renewcommand*{\l@chapter}[2]{%
  \stdl@chapter{\textcolor{headercolor}{#1}}{\textcolor{headercolor}{#2}}}
\makeatother

\setcounter{tocdepth}{4}
\setcounter{secnumdepth}{4}
\shorttableofcontents{Inhalts\"ubersicht}{1}
\bookmark[page=15,rellevel=1,keeplevel,view={XYZ},color=red]{Inhalts\"ubersicht}
\bookmark[page=17,rellevel=1,keeplevel,view={XYZ},color=red]{Inhaltsverzeichnis}
\tableofcontents
\clearpage
\pagenumbering{arabic}  
%

%\pagestyle{mystyle}
\mainmatter%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pagestyle{fancy}
\fancyhf{}
%\fancyhead[L]{\parbox{0.7\textwidth}{\textbf{ \textcolor{headercolor}\leftmark\textcolor{headercolor}{\rightmark}}}}
%\fancyhead[L]{ \textcolor{headercolor}{\rightmark}}%\thesection%\textcolor{headercolor}\text{ }\leftmark \text{ }


\fancyhead[L]{\hspace{2mm}\textcolor{headercolor}{\leftmark}\text{ }\textcolor{headercolor}{\rightmark}\hfill\textcolor{headercolor}{\thepage}\hspace{4mm}}
\renewcommand{\headrule}{\vspace{-\headheight}\textcolor{headercolor}{\vrule height \headheight width 2pt\relax\rule{\textwidth-8pt}{2pt}\vrule height \headheight width 2pt\relax}}

%\include{part1} 
%\include{chapter1}
%\include{chapter2}
%\include{part2}
%\include{chapter3}
%\include{chapter4}
%\include{chapter5}
%\include{chapter6}
\backmatter

\appendix 

\include{appendix}

\listoffigures
\newpage
\listoftables
\backmatter%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\include{glossary}
%\include{solutions}
\cleardoublepage
\phantomsection
\addcontentsline{toc}{part}{Index}
\printindex

\cleardoublepage
\phantomsection
\addcontentsline{toc}{part}{the author}
%\includepdf{author}
%\includepdf{back}
\end{document}

我给了你这么多代码,因为我不知道我的错误在哪里?

答案1

如果你想排版一切用倾斜的 Helvetica 粗体字体,然后

\renewcommand{\rmdefault}{phv}
\renewcommand{\sfdefault}{phv}
\renewcommand{\mddefault}{b}
\renewcommand{\bfdefault}{b} % Helvetica has no bx series
\renewcommand{\updefault}{sl}

在你的序言中这样写就够了。我认为这不是一个好主意。

答案2

M 代表最小。

  1. 已经有一个用于字体设置的宏:

    \usefont{T1}{phv}{b}{sl}
    
  2. 您想在序言中使用哪种字体?没有要排版的文本。

    您可能想要设置标题的字体。您必须将其包含\usefont在标题的定义中。

在这个 MWE 中,甚至你的命令也能起作用:

\documentclass{book}

\usepackage[T1]{fontenc}

\usepackage{mathptmx}
\usepackage{helvet}

\begin{document}
\usefont{T1}{phv}{b}{sl}
Testing
\end{document}

对于标题的更改确实包括 \changefont/\usefont在其定义中,例如,

\usepackage[pagestyles]{titlesec}

\titleformat{\section}
{\usefont{T1}{phv}{b}{n}\Large\bfseries}{\thesection}{1em}{}

要更改正文字体,请使用以下命令:

\renewcommand*{\rmdefault}{phv}

(但由于 ,因此自动使用 Helvetica \usepackage{helvet}。)

相关内容