设置小页面中图标的大小 | FontAwesome5

设置小页面中图标的大小 | FontAwesome5

首先,我想说我的“问题”既不根本也不重要。只是我看到了它,却无法忘怀……就像黑板上的一小块粉笔,不重要却很烦人。

两个带有 mdframed 的注释,然后是两个部分的 minipage

我们看到这些图标很漂亮。但是图标的“大小”(此处为 \fontsize)是手写的,此处为 20pt。

所以我想知道是否有办法做到这一点,而无需手动配置字体大小。

完美的事情是,如果它们需要\linewidth(但我不确定像我的例子上的感叹号这样的小东西)......也许是类似的东西\renewcommand{\fontsize}{\the\linewidth},然后把它们写在一起\textsf{•},使它们具有相同的宽度。

同一张图片,带有评论,以防万一有帮助: 同张图片,有评论

我看见这个帖子。我只是不知道如何使它适应 FontAwesome 的图标...考虑到它是一种字体而不是图片。

以下是此部分的代码:

% Boxes
%
% \annotation
%   {color}
%   {icon}
%   {text}
\newcommand\annotation[3]
{
\begin{mdframed}[
    innerlinewidth    = 2pt   ,
    roundcorner       = 10pt  ,
    innerlinewidth    = 0pt   ,
    middlelinewidth   = 0pt   ,
    outerlinewidth    = 0pt   ,
    innerleftmargin   = 10pt  ,
    innerrightmargin  = 10pt  ,
    innertopmargin    = 10pt  ,
    innerbottommargin = 10pt  ,
    leftmargin        = 0.5cm ,
    rightmargin       = 0.5cm ,
    skipabove         = 0.5cm ,
    skipbelow         = 0.1cm ,
    backgroundcolor   = #1!10
    ]
    \begin{minipage}{0.075\linewidth}
        \begin{center}
            \textcolor{#1}{\fontsize{20pt}{20pt}\selectfont\faIcon{#2}}
        \end{center}
    \end{minipage}
    \begin{minipage}{0.9\linewidth}
        \textit{\color{#1!70}#3}
    \end{minipage}
\end{mdframed}
}

以下是供您使用的示例代码:

\documentclass{report}
\usepackage[framemethod=tikz]{mdframed} % https://www.ctan.org/pkg/mdframed

% color         -> color        https://www.ctan.org/pkg/color
% tikzpagenodes -> draw figures https://www.ctan.org/pkg/tikzpagenodes
% fontawesome5  -> icons        https://www.ctan.org/pkg/fontawesome5
\usepackage{color, tikzpagenodes, fontawesome5}

% Defines the colors
\definecolor{theme}{HTML}{438DCC}
\definecolor{internalLink}{HTML}{707070}

% Boxes
%
% \annotation
%   {color}
%   {icon}
%   {text}
\newcommand\annotation[3]
{
\begin{mdframed}[
    innerlinewidth    = 2pt   ,
    roundcorner       = 10pt  ,
    innerlinewidth    = 0pt   ,
    middlelinewidth   = 0pt   ,
    outerlinewidth    = 0pt   ,
    innerleftmargin   = 10pt  ,
    innerrightmargin  = 10pt  ,
    innertopmargin    = 10pt  ,
    innerbottommargin = 10pt  ,
    leftmargin        = 0.5cm ,
    rightmargin       = 0.5cm ,
    skipabove         = 0.5cm ,
    skipbelow         = 0.1cm ,
    backgroundcolor   = #1!10
    ]
    \begin{minipage}{0.075\linewidth}
        \begin{center}
            \textcolor{#1}{\fontsize{20pt}{20pt}\selectfont\faIcon{#2}}
        \end{center}
    \end{minipage}
    \begin{minipage}{0.9\linewidth}
        \textit{\color{#1!70}#3}
    \end{minipage}
\end{mdframed}
}

\begin{document}

\annotation
    {theme}
    {comment}
    {Le document a été configuré pour ouvrir les liens dans un nouvel onglet, afin de ne pas écraser celui dans lequel ce trouve le document par une redirection (Si ce document est ouvert dans un navigateur).}
\annotation
    {red}
    {exclamation}
    {À ne pas confondre avec les éléments du document, ces derniers portent la même couleur mais en style standard (en non sans Sherif).}

\end{document}

完整代码如下:

\documentclass[12pt, french]{report}
\usepackage[a4paper, total={5.65in, 9.1in}]{geometry} % https://www.ctan.org/pkg/geometry
\usepackage[utf8]{inputenc}                           % https://www.ctan.org/pkg/inputenc
\usepackage[T1]{fontenc}                              % https://www.ctan.org/pkg/fontenc
\usepackage[final]{pdfpages}                          % https://www.ctan.org/pkg/pdfpages
\usepackage[parfill]{parskip}                         % https://www.ctan.org/pkg/parskip
\usepackage[style=numeric]{biblatex}                  % https://www.ctan.org/pkg/biblatex
\usepackage[framemethod=tikz]{mdframed}               % https://www.ctan.org/pkg/mdframed

% babel         -> language                                          https://www.ctan.org/pkg/babel
% color         -> color                                             https://www.ctan.org/pkg/color
% tikzpagenodes -> draw figures                                      https://www.ctan.org/pkg/tikzpagenodes
% fancyhdr      -> stylize header and footer                         https://www.ctan.org/pkg/fancyhdr
% fontawesome5  -> icons                                             https://www.ctan.org/pkg/fontawesome5
% hyperref      -> hyperlink                                         https://www.ctan.org/pkg/hyperref
% titlesec      -> stylize chapter and sections                      https://www.ctan.org/pkg/titlesec
% csquotes      -> because ' can cause graphical problems with babel https://www.ctan.org/pkg/csquotes
% enumitem      -> control over list environments                    https://www.ctan.org/pkg/enumitem
\usepackage{babel, color, tikzpagenodes, fancyhdr, fontawesome5, hyperref, titlesec, csquotes, enumitem}

% Bibliography
\addbibresource{ref.bib}

% Defines the colors
\definecolor{theme}{HTML}{438DCC}
\definecolor{internalLink}{HTML}{707070}

% For header and footer
\fancypagestyle{plain}{
    \fancyhf{} % Remove what was before
    \setlength{\headheight}{15pt}
    \renewcommand{\headrulewidth}{0pt}  % Remove the rule after the header
    
    % head -> header
    % foot -> footer
    % l    -> left
    % c    -> center
    % r    -> right
    \lhead{
        \begin{tikzpicture}[remember picture,overlay]
        \node[xshift=-8.93cm, yshift=-1.94cm] at (current page.north) {\includegraphics{Autre/Header.pdf}};
        \end{tikzpicture}
        \textbf{\textsc{\textcolor{white}{M}argot} Louis}
    }
    \rhead{\textbf{Rapport de stage}}
    \cfoot{\textbf{\textcolor{theme}{--}~\thepage~\textcolor{theme}{--}}}
    \rfoot{
        \begin{tikzpicture}[remember picture,overlay]
        \node[xshift=9cm, yshift=0.8cm] at (current page.south) {\includegraphics{Autre/Footer.pdf}};
        \end{tikzpicture}
    }
}
\pagestyle{plain}

% Hyperlinks
\hypersetup{
    pdfinfo={
        Title={Rapport de stage},
        Subject={Conception marketing: Web design, développement},
        Author={MARGOT louis}
    },
    linktoc=page,
    colorlinks=true,
    filecolor=theme,
    menucolor=theme,
    urlcolor=theme,
    linkcolor=internalLink,
    citecolor=internalLink,
    pdfnewwindow=true,
    bookmarksnumbered=true,
    bookmarksopen=true
}

% Lorem ipsum
\usepackage{lipsum} 

% Personalization ToC
\setcounter{secnumdepth}{1}
\setcounter{tocdepth}{2}

% Personalization chapter and sections
%
% \titleformat{<command>}[<shape>]{<format>}{<label>}{<sep>}{<before-code>}[<after-code>]
%   <command> is the sectioning command to be redefined: \part, \chapter, \section, \subsection, \subsubsection, \paragraph or \subparagraph.
%   <shape> is sectioning paragraph shape; possible values are: hang, block, display, runin, leftmargin, rightmargin, drop, wrap, frame.
%   <format> is the format to be applied to the title, label, and text; for example \normalfont\Large\bfseries
%   <label> specify sectioning label.
%   <sep> is the horizontal separation between label and title body and it must be a length and not be empty.
%   <before-code> is code preceding the title body.
%   <after-code> is code following the title body.
\titleformat{\chapter}[hang]{\normalfont\Huge\bfseries}{\thechapter\hspace{20pt}\textcolor{theme}{|}\hspace{20pt}}{0pt}{\Huge\bfseries}
\titleformat{\section}[hang]{\normalfont\Large\bfseries}{\thesection\hspace{15pt}\textcolor{theme}{|}\hspace{15pt}}{0pt}{\normalfont\Large\bfseries}
\titleformat{\subsection}[hang]{\normalfont\large\bfseries}{\textcolor{theme}{|}\hspace{10pt}}{0pt}{\normalfont\large\bfseries}
\titleformat{\subsubsection}[hang]{\normalfont\normalsize\bfseries}{\textcolor{theme}{|}\hspace{5pt}}{0pt}{\normalfont\normalsize\bfseries}
\titleformat{name=\chapter,numberless}[hang]{\normalfont\Huge\bfseries}{}{0pt}{\textcolor{theme}{|}\hspace{20pt}}
\titleformat{name=\section,numberless}[hang]{\normalfont\Large\bfseries}{}{0pt}{\textcolor{theme}{|}\hspace{15pt}}
\titleformat{name=\subsection,numberless}[hang]{\normalfont\large\bfseries}{}{0pt}{\textcolor{theme}{|}\hspace{10pt}}
\titleformat{name=\subsubsection,numberless}[hang]{\normalfont\normalsize\bfseries}{}{0pt}{\textcolor{theme}{|}\hspace{5pt}}

% Personalization lists
\setlist[itemize]{label=\textcolor{theme}{---}}
\setlist[enumerate]{label=\textcolor{theme}{\arabic*.}}

% Boxes
%
% \annotation
%   {color}
%   {icon}
%   {text}
\newcommand\annotation[3]
{
\begin{mdframed}[
    innerlinewidth    = 2pt   ,
    roundcorner       = 10pt  ,
    innerlinewidth    = 0pt   ,
    middlelinewidth   = 0pt   ,
    outerlinewidth    = 0pt   ,
    innerleftmargin   = 10pt  ,
    innerrightmargin  = 10pt  ,
    innertopmargin    = 10pt  ,
    innerbottommargin = 10pt  ,
    leftmargin        = 0.5cm ,
    rightmargin       = 0.5cm ,
    skipabove         = 0.5cm ,
    skipbelow         = 0.1cm ,
    backgroundcolor   = #1!10
    ]
    \begin{minipage}{0.075\linewidth}
        \begin{center}
            \textcolor{#1}{\fontsize{20pt}{20pt}\selectfont\faIcon{#2}}
        \end{center}
    \end{minipage}
    \begin{minipage}{0.9\linewidth}
        \textit{\color{#1!70}#3}
    \end{minipage}
\end{mdframed}
}

\begin{document}
\include{paper}
\end{document}

感谢您的阅读,希望我们能够一起解决问题!

--玛格特·路易斯--

答案1

如果您希望字体大小与线宽相同,则只需\fontsize{20pt}{20pt}用替换即可\fontsize{\linewidth}{\linewidth}

但是官方的 Font Awesome JavaScript 代码始终将固定宽度图标的宽度设置为 1.5em,因为有些图标比字体大小更宽。因此我建议改用0.666\linewidth。(因为 0.666 大约是 1/1.5):

\documentclass{report}
\usepackage[framemethod=tikz]{mdframed} % https://www.ctan.org/pkg/mdframed

% color         -> color        https://www.ctan.org/pkg/color
% tikzpagenodes -> draw figures https://www.ctan.org/pkg/tikzpagenodes
% fontawesome5  -> icons        https://www.ctan.org/pkg/fontawesome5
\usepackage{color, tikzpagenodes}
\usepackage[fixed]{fontawesome5}

% Defines the colors
\definecolor{theme}{HTML}{438DCC}
\definecolor{internalLink}{HTML}{707070}

% Boxes
%
% \annotation
%   {color}
%   {icon}
%   {text}
\newcommand\annotation[3]
{
\begin{mdframed}[
    innerlinewidth    = 2pt   ,
    roundcorner       = 10pt  ,
    innerlinewidth    = 0pt   ,
    middlelinewidth   = 0pt   ,
    outerlinewidth    = 0pt   ,
    innerleftmargin   = 10pt  ,
    innerrightmargin  = 10pt  ,
    innertopmargin    = 10pt  ,
    innerbottommargin = 10pt  ,
    leftmargin        = 0.5cm ,
    rightmargin       = 0.5cm ,
    skipabove         = 0.5cm ,
    skipbelow         = 0.1cm ,
    backgroundcolor   = #1!10
    ]
    \begin{minipage}{0.075\linewidth}
        \begin{center}
            \textcolor{#1}{\fontsize{0.666\linewidth}{0.666\linewidth}\selectfont\faIcon{#2}}
        \end{center}
    \end{minipage}
    \begin{minipage}{0.9\linewidth}
        \textit{\color{#1!70}#3}
    \end{minipage}
\end{mdframed}
}

\begin{document}

\annotation
    {theme}
    {comment}
    {Le document a été configuré pour ouvrir les liens dans un nouvel onglet, afin de ne pas écraser celui dans lequel ce trouve le document par une redirection (Si ce document est ouvert dans un navigateur).}
\annotation
    {red}
    {exclamation}
    {À ne pas confondre avec les éléments du document, ces derniers portent la même couleur mais en style standard (en non sans Sherif).}

\end{document}

相关内容