Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

In my current latex report, I have to insert code snippets into Latex table. I have tried with listing but, listing is not working. I have written following latex code using verbatim. But, I want some professional look. Could you suggest me -- how could I insert code snippet in latex table ?

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}
share|improve this question

migrated from stackoverflow.com Nov 26 '12 at 12:55

This question came from our site for professional and enthusiast programmers.

add comment

1 Answer

up vote 2 down vote accepted

listings is working.

Add to your preambule:

\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}
}
{}

In the table's cell:

% 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

Note opening and closing curve brackets before and after mylist environment.

share|improve this answer
    
Many Many thanks Redmode. –  Pankesh Patel Nov 26 '12 at 9:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.