1

From this longtable:

\begingroup
\setlength{\LTleft}{-20cm plus -1fill}
\setlength{\LTright}{\LTleft}
\begin{small}
    \begin{longtable}{ |p{1cm}|p{5cm}|p{7cm}| }
        \caption{Tabel Pustaka Librosa} \label{tbl:lib_Librosa}\\
        \hline
        \textbf{No} & \textbf{\textit{Function}} & \textbf{Deskripsi}\\
        \endfirsthead
        \multicolumn{3}{c}{\textbf{\tablename~\thetable} Tabel Librosa (Lanjutan)}\\
        \hline
        \textbf{No} & \textbf{\textit{Function}} & \textbf{Deskripsi}\\
        \endhead
        \hline
        1 & librosa.load(\textit{filename}) & blablabla\\
        \hline
        2 & librosa.core.spectrum.stft(x, n\_fft = window\_size, hop\_length = hop\_length, window=window) & blablabla\\
        \hline
    \end{longtable}
\end{small}
\endgroup

I want to change these:

1 & librosa.load(\textit{filename})
2 & librosa.core.spectrum.stft(x, n\_fft = window\_size, hop\_length = hop\_length, window=window)

into a different font-family: Consolas.

My document now is using Times New Roman font-family. Is there a way I can change only some of the text inside the table into a different font family?

This is my preamble. You can ignore the comments written in Bahasa Indonesia.

% Tipe dokumen adalah report dengan satu kolom. 
% Mengatur setting halaman 
\documentclass[12pt, a4paper, onecolumn, oneside, final]{report}
\makeatother

\usepackage{array}
\setlength\extrarowheight{4pt}

\usepackage{tabto}
\newenvironment{tabs}[1]
{\TabPositions{#1}}

\usepackage{longtable}  
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}p{#1}}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}

% Hyperlink untuk section, link, citation 
\usepackage{hyperref}
\urlstyle{same}
\hypersetup{
    colorlinks=true,
    linkcolor=blue,
    citecolor=green,
    filecolor=magenta,      
    urlcolor=blue
}

% Load konfigurasi LaTeX untuk tipe laporan thesis ITHB
\usepackage{if_ithb} 

\usepackage{adjustbox}
\usepackage{algcompatible}
\usepackage[chapter,Algorithm,ruled]{algorithm}
\usepackage{algorithm}
\usepackage{algorithmicx}
\usepackage{algpseudocode}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{caption}
\usepackage{colortbl}
\usepackage{enumitem}
\usepackage{etoolbox}
\usepackage{float}
\usepackage{fon tenc}
\usepackage{gensymb}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{mathtools}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{musicography}
\usepackage{pdflscape}
\usepackage{pifont}
\usepackage{ragged2e}
\usepackage{rotating}
\usepackage{subcaption}
\usepackage{tabu}
\usepackage{textcomp}
\usepackage{tocloft}
\usepackage{xcolor}

\newcommand\listappendixname{DAFTAR LAMPIRAN}
\newcommand\appcaption[1]{%
   \addcontentsline{app}{chapter}{#1}}
\makeatletter
\newcommand\listofappendices{%
   \chapter*{\listappendixname}\@starttoc{app}}
\makeatother

% Daftar pemenggalan suku kata dan istilah dalam LaTeX
\include{hype.indonesia}

% Variabel baru untuk menyimpan nomor halaman
\newcounter{originalpagenumber}%
\renewcommand\cftchapdotsep{\cftdotsep}%

% Daftar isi, supaya subsubsection terindeks juga
\setcounter{tocdepth}{4}

% Awal bagian penulisan laporan
\begin{document}

    % Sampul Laporan
    \include{sampul_luar}
    
    % Sampul Laporan - dalam
    \include{sampul_dalam}
    
    % Daftar isi, gambar, dan tabel
    % Gunakan penomeran Romawi (i, ii, iii, ...) setelah bagian ini.
%    \captionsetup{justification=centering}
%    \newcolumntype{P}[1]{>{\RaggedRight\arraybackslash}p{#1}}
%    \makeatletter

    \newcounter{savepage}
    \pagenumbering{roman}
    
    % Halaman Penyataan Orisinalitas
    %\include{halaman_pernyataan_orisinalitas}
    
    % Halaman Pengesahan
    %\include{halaman_pengesahan}
    
    % Halaman Publikasi
    %\include{halaman_publikasi}
 
    % Lembar Abstrak
    % \phantomsection \addcontentsline{toc}{chapter}{ABSTRAK}
    %\include{abstrak}

    % Lembar Abstract
%   \phantomsection \addcontentsline{toc}{chapter}{ABSTRACT}
    %\include{abstract}

    % Lembar Pedoman
%   \phantomsection \addcontentsline{toc}{chapter}{PEDOMAN PENGGUNAAN TUGAS AKHIR}
    %\include{pedoman}

    % Kata Pengantar
%   \phantomsection \addcontentsline{toc}{chapter}{KATA PENGANTAR}
    %\include{kata_pengantar}
    
    \vspace*{-2.5cm}
    \phantomsection \addcontentsline{toc}{chapter}{DAFTAR ISI}
    \tableofcontents
    \clearpage
    
    \vspace*{-2.5cm}
    \phantomsection \addcontentsline{toc}{chapter}{DAFTAR TABEL}
    \listoftables
    \clearpage
    
    \vspace*{-2.5cm}
    \phantomsection \addcontentsline{toc}{chapter}{DAFTAR GAMBAR}
    \listoffigures
    
    \vspace*{-2.5cm}
    \phantomsection \addcontentsline{toc}{chapter}{DAFTAR LAMPIRAN}
    \listofappendices
    \clearpage
    
    \setcounter{savepage}{\arabic{page}}
    \makeatletter
    \def\MyPagenumbering#1{%
        \global\c@page \@ne \gdef\thepage{\arabic{chapter}-\csname @#1\endcsname
            \c@page}}
    \makeatother
    \pagestyle{fancy}
    \renewcommand{\chaptermark}[1]{%
        \markboth{BAB \thechapter \ #1}{}}
    
    \fancyhf{}
    % Gunakan penomeran Arab (1, 2, 3, ...) setelah bagian ini.
    \MyPagenumbering{arabic}
    
    % Untuk mengatur posisi pagenumber
    %\pagestyle{plain}
    \setlength\LTleft{0pt}            % default: \fill
    \setlength\LTright{0pt}           % default: \fill
    \lhead{\leftmark}
    \renewcommand{\headrulewidth}{1pt}
    
    \fancypagestyle{plain}{%
        \renewcommand{\headrulewidth}{0pt}%
        \fancyhf{}%
        \fancyfoot[R]{\arabic{chapter}-1}%
    }
    
    \onehalfspacing
    \rfoot{\arabic{chapter}-\arabic{page}}
    
    \setcounter{page}{1}
    \include{bab1}

    \setcounter{page}{1}
    \include{bab2}

    \setcounter{page}{1}
    \include{bab3}

    \setcounter{page}{1}
    \include{bab4}

    \setcounter{page}{1}
    \include{bab5}
    

    \pagenumbering{roman}
    \setcounter{page}{\thesavepage}
    \fancypagestyle{plain}{%
        \renewcommand{\headrulewidth}{0pt}%
        \fancyhf{}%
        \fancyfoot[c]{\thepage}%
    }
    \rfoot{\thepage}

    % Daftar Pustaka
    \renewcommand{\bibname}{DAFTAR REFERENSI}
    \setcounter{page}{1}
    \phantomsection \addcontentsline{toc}{chapter}{DAFTAR REFERENSI}
    \include{pustaka}
    \cftsetindents{chap}{0pt}{\mylen}
    
    % Lampiran 
    \pagestyle{fancy}
    \renewcommand{\chaptermark}[1]{
        \markboth{LAMPIRAN \thechapter \ #1}{}}
        
    \pagenumbering{arabic} 
    \setcounter{page}{1}
    \setcounter{table}{0}
    \renewcommand{\thepage}{A-\arabic{page}}
    \renewcommand{\thetable}{\Alph{chapter}-\arabic{table}}
    \renewcommand{\thepage}{\Alph{chapter}-\arabic{page}}
    
    \renewcommand\cftchappresnum{LAMPIRAN}
    
    \begin{appendix}
        \include{lampiran}
        \rfoot{\Alph{chapter}-\arabic{page}}
    \end{appendix}
    
\end{document}

Inside if_ithb package, this is an .sty file.

% Mengatur bahasa latex
\usepackage[bahasa]{babel}
\usepackage[utf8]{inputenc}

% Untuk pengaturan spacing
\usepackage{setspace}
\onehalfspacing

% Untuk mengatur level section 
\setcounter{secnumdepth}{6}

% Digunakan untuk memasukan gambar ke laporan. 
\usepackage{graphicx}

% Untuk mengatur spacing antara paragraf
\usepackage{parskip}

% Membuat indent
\usepackage{indentfirst}
\setlength\parindent{1.5cm}

% Untuk mengkustomisasi margin
\usepackage{scrextend}

% Untuk mengatur header dan footer
\usepackage{fancyhdr}

% Membuat seluruh tulisan menjadi Times New Roman. 
\usepackage{pslatex}

% Merubah numbering chapter dan section untuk judul setiap bab menggunakan romawi dan judul anak bab menggunakan arabic
\renewcommand{\thesection}{\arabic{chapter}.\arabic{section}\hspace{0,3cm}}
\renewcommand{\thesubsection}{\arabic{chapter}.\arabic{section}.\arabic{subsection}}
\renewcommand{\thesubsubsection}{\arabic{chapter}.\arabic{section}.\arabic{subsection}.\arabic{subsubsection}\hspace{-0,35cm}}


% Merubah huruf kapital pada judul daftar isi, daftar gambar, dan daftar table
\usepackage{tocloft}
\renewcommand{\cfttoctitlefont}{\hfil\large\bfseries\MakeUppercase}
\renewcommand{\cftloftitlefont}{\hfil\large\bfseries\MakeUppercase}
\renewcommand{\cftlottitlefont}{\hfil\large\bfseries\MakeUppercase}

\renewcommand\cftchappresnum{BAB }
\renewcommand\cftchapaftersnum{}
\newlength\mylen
\settowidth\mylen{\bfseries BAB 1 :\ } % if more than 9 chapters, use "Chapter 10"
\cftsetindents{chap}{0pt}{\mylen}

% Mengatur font section
\usepackage{sectsty}
\sectionfont{\fontsize{12}{14}\selectfont}
\subsectionfont{\fontsize{12}{14}\selectfont}
\subsubsectionfont{\fontsize{12}{14}\selectfont}

% Untuk merupakan format penulisan BAB
\usepackage{titlesec}   
\titleformat{\chapter}
    {\doublespacing\fontsize{14pt}{16pt}\bfseries}
    {\MakeUppercase{\chaptertitlename\ \thechapter}\filcenter}      {0.15cm}{\centering\uppercase}
\titlespacing*{\chapter}{0pt}{-1cm}{20pt}

% Mengatur spacing section
\titlespacing*{\section}
{0pt}{0pt}{-0.05cm}
\titlespacing*{\subsection}
{0pt}{0pt}{-0.05cm}
\titlespacing*{\subsubsection}
{0pt}{0pt}{-0.05cm}
    
% Digunakan untuk mengatur caption dalam dokumen.
\usepackage[font=footnotesize,format=plain,labelfont=bf,up,textfont=up]{caption}
% Untuk menghapus titik dua (colon)
\captionsetup[figure]{labelsep=space}
\captionsetup[table]{labelsep=space}

% Mengatur nomor caption gambar
\renewcommand{\thefigure}{\arabic{chapter}.\arabic{figure}}

% Mengatur nomor caption table
\renewcommand{\thetable}{\arabic{chapter}.\arabic{table}}

% Mengatur Hyphenation pada latex
\tolerance=1
\emergencystretch=\maxdimen
\hyphenpenalty=10000
\hbadness=10000

% Untuk mengatur setting indent
\setlength\parindent{1.30cm}

% Untuk memasukkan table
\usepackage{tabularx}

% Untuk mengatur width
\usepackage{changepage}

% Menggatur setting halaman 
\usepackage{geometry}
\geometry{
  left=4cm,            % <-- you want to adjust this
  top=3cm,
  right=3cm,
  bottom=3cm,
}

% Teks testing
\usepackage{blindtext}
\usepackage{lipsum}

% Untuk mengatur subscript supscript
\usepackage{fixltx2e}

% Untuk mengatur wrap picture
\usepackage{wrapfig}

% Untuk notasi matematika
\usepackage{amsmath}
\usepackage{stmaryrd}
\usepackage{mathtools}
% untuk mengatur label nomor pada rumus
\renewcommand{\theequation}{\arabic{chapter}.\arabic{equation}}

% Untuk mengatur spacing daftar gambar
\newcommand*{\noaddvspace}{\renewcommand*{\addvspace}[1]{}}
\addtocontents{lof}{\protect\noaddvspace}

%untuk mengatur package include table in excel
% \usepackage{pgfplotstable}

% untuk mengatur landscape page
\usepackage{rotating}
11
  • 2
    Add the line \setmonofont{Consolas}[Scale=MatchUppercase] to your preamble. Wrap the text you want to change in \texttt{...}. – Davislor Feb 27 at 14:12
  • 1
    After you load \setmainfont and before \begin{document}. – Davislor Feb 27 at 14:16
  • 1
    A: Switch to LuaLaTeX, which will also let you clean a lot of packages out of your preamble. B: Pick a different monospace font that does have support for PDFTeX, such as \usepackage{inconsolata} – Davislor Feb 27 at 14:48
  • 1
    For example, textcomp and \usepackage[utf8]{inputenc} are now part of the LaTeX kernel and no longer needed. The pslatex package is pretty out of date; psnfss is newer, but you might get more-consistent results using a font that ships with TeX and that you know will be the same everywhere, such as tgtermes. – Davislor Feb 27 at 14:52
  • 1
    @Davislor "pslatex pretty out of date" ? next you will telling me you don't still use a 1980's laser writer with 16 built in postscript fonts? – David Carlisle Feb 27 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.