在我当前的 Latex 报告中,我必须将代码片段插入到 Latex 表中。我尝试过,listing
但是,列表不起作用。我使用以下乳胶代码编写了逐字。但是,我想要一些专业的外观。你能给我建议吗——如何在乳胶表中插入代码片段?
begin{sidewaystable}[ht]
\small
\centering
\begin{tabular}{ | >{\raggedright}p{4cm} | >{\raggedright}p{4cm}| >{\raggedright}p{7cm} | >{\raggedright}p{9cm} |} \hline
\textbf{Domain/Application} & \textbf{Vocabulary} & \textbf{Network} & \textbf{Architecture/Computational Logic} \cr \hline
\emph{Building-Automation Domain} \vspace{0.1in} \\ Regulating Temperature \\ \vspace{0.5in} Detecting Fire & \begin{verbatim}
regions:
Building : integer;
Floor: integer;
Room : integer;
abilities:
sensors:
TemperatureSensor
SmokeDetector
BadgeReader
actuators:
Heater
Alarm
\end{verbatim}
& \begin{verbatim}
Device 1:
Ability: TemperatureSensor
Location: Building 1, Floor 2, Room 2
Device 2:
Ability: SmokeDetector, TemperatureSensor
Location: Building 1, Floor 2, Room 2
\end{verbatim} & \begin{verbatim}
AverageTemperature:
generate AverageTemperature : TempStruct ;
consume AvgTempMeasurement from hops: 0 : Room;
in - region : Building | Floor | Room ;
FireAlarmComputation
generate FireAlarmState : FireAlarmStruct ;
consume AverageTemperature from hops : 0 : Room ;
consume SmokeDetector from hops : 0 : Room ;
in - region : Room ;
\end{verbatim}
\cr \hline
\end{tabular}
\caption{}
\label{vsdfasdfasfada}
\end{sidewaystable}
答案1
listings
工作中。
添加到您的序言中:
\usepackage{listings}
\usepackage{xcolor}
% Listings style
\newcommand\mystyle{\lstset{
language=R, % Specify your language here
basicstyle=\ttfamily, % Specify basic style
otherkeywords={Device,Abilty}, % Keywords
keywordstyle=\color{red} % Add other options
}}
% Custom environment for your listings
\lstnewenvironment{mylist}[1][]
{
\mystyle
\lstset{#1}
}
{}
在表格的单元格中:
% Previous cell here
&
{\begin{mylist}
Device 1:
Ability: TemperatureSensor
Location: Building 1, Floor 2, Room 2
Device 2:
Ability: SmokeDetector, TemperatureSensor
Location: Building 1, Floor 2, Room 2
\end{mylist}}
&
% Next cell here
注意环境前后的曲线括号的打开和关闭mylist
。