缩小列表中的字体大小

缩小列表中的字体大小

我正在使用 latex beamer,并尝试减小列表的字体大小以显示整个 JSON 代码,而不减小之前句子的字体大小。我该如何让它工作?

在此处输入图片描述

代码:

\documentclass[xcolor=dvipsnames]{beamer}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usetheme{Antibes}
\usecolortheme[named=Maroon]{structure} 
\setbeamercovered{transparent}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{xcolor}
\usepackage{listings}

\newcommand\JSONnumbervaluestyle{\color{red}}
\newcommand\JSONstringvaluestyle{\color{red}}

% switch used as state variable
\newif\ifcolonfoundonthisline

\makeatletter

\lstdefinestyle{json}
{
  showstringspaces    = false,
  alsoletter          = 0123456789.,
  morestring          = [s]{"}{"},
  stringstyle         = \ifcolonfoundonthisline\JSONstringvaluestyle\fi,
  MoreSelectCharTable =%
    \lst@DefSaveDef{`:}\colon@json{\processColon@json},
  basicstyle          = \ttfamily,
  keywordstyle        = \ttfamily\bfseries,
}

% flip the switch if a colon is found in Pmode
\newcommand\processColon@json{%
  \colon@json%
  \ifnum\lst@mode=\lst@Pmode%
    \global\colonfoundonthislinetrue%
  \fi
}

\lst@AddToHook{Output}{%
  \ifcolonfoundonthisline%
    \ifnum\lst@mode=\lst@Pmode%
      \def\lst@thestyle{\JSONnumbervaluestyle}%
    \fi
  \fi
  %override by keyword style if a keyword is detected!
  \lsthk@DetectKeywords% 
}

% reset the switch at the end of line
\lst@AddToHook{EOL}%
  {\global\colonfoundonthislinefalse}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\title{Test}
\author{Alex XYZ}
\institute{University XYZ}
\date{20.01.16}



\begin{document}
\beamertemplatenavigationsymbolsempty

\begin{frame}
\titlepage
\end{frame}

\begin{frame}[fragile]{JSON array of the timetable sheets}

JSON array of the parsed timetable sheets:
\bigbreak


\begin{lstlisting}[style=json]

        [{"stops": [{
                     "arrival_time": {
                                       "mon-fri": [ "04:31", "04:43"],
                                      "sat":     ["05:32", "06:32"],                                     
                                      "sun":     ["05:32", "06:32"]
                                      },   
                     "stop_name": "XYZ",
                     "stop_lat": "90.874136",
                     "stop_long": "19.665553"
                    }]
         }]
\end{lstlisting}
\end{frame}

\end{document}

答案1

只需将字体大小添加到基本样式中,例如,

basicstyle = \ttfamily\small,

当然,有了这么大的缩进,你就需要更小的字体了:

如果你

\begin{lstlisting}[style=json,basicstyle=\ttfamily\tiny]
        [{"stops": [{
                     "arrival_time": {
                                       "mon-fri": [ "04:31", "04:43"],
                                      "sat":     ["05:32", "06:32"],
                                      "sun":     ["05:32", "06:32"]
                                      },
                     "stop_name": "XYZ",
                     "stop_lat": "90.874136",
                     "stop_long": "19.665553"
                    }]
         }]
\end{lstlisting}

你得到

在此处输入图片描述

相关内容