Possible Duplicate:
How to align comments with lstlistings?
I want to include Matlab code with long comments. The next MWE shows that it is achieved by using the listings package. However I would like these long comments to be aligned when they are split in several lines, i.e. I want to align all the % in my final output. Note that the comments need not to be aligned in the original listing!
\documentclass{article}
\usepackage{fullpage}
\newcommand\sample{Some text to experiment with line numbering. }
\usepackage{listings}
\lstset{language=Matlab}
\lstset{tabsize=2}
\lstset{
language={Matlab},
keepspaces=true,
basicstyle=\small,
xleftmargin=\parindent,
xrightmargin=\parindent,
frame=single,
framesep=2mm,
framerule=0pt,
frame=single,
columns=flexible}
\lstset{postbreak=\raisebox{0ex}[0ex][0ex]{\ensuremath{\%}}}
\lstset{breaklines=true, breakindent=10cm, breakatwhitespace=true}
\begin{document}
\sample \sample \sample \sample \sample
\begin{minipage}[c]{\textwidth}
\begin{lstlisting}[language=Matlab, linewidth=15cm]
clear all; clc; close all % Clear all variables, close all figures and clear workspace
Data=randi([2 7], 1, 20) % Generate a random sample with 20 elements
Table = [DataValue', Frequency', RelFreq, CumRelFreq] % Generate a table with the previous results
\end{lstlisting}
\end{minipage}
\end{document}
Could someone let me know if this is possible?
matlab-prettifierpackage; see this answer. – jub0bs Apr 28 '14 at 16:32