Seite 1 von 1

Abstand zwischen dem Absatz und Algorithm hinzufügen.

Verfasst: Sa 3. Okt 2015, 16:56
von the_time
Hallo zusammen,

es geht mir um die erste Frage aber wenn jemand es weißt und Lust hat, kann er auch gerne die 2te und 3te Frage beantworten :) .

1. wie kann ich Abstand zwischen dem Absatz und Algorithm sowie zwischen dem Algorithm und Listing hinzufügen?
2. wie kann ich Numierung zu den Algorithm-Zeilen hinzufügen?
3. wie kann ich comment im Algorithm schreiben?

Schöne Grüße,
the_time

Code
\documentclass{article}
\usepackage[ruled]{algorithm2e}
\renewcommand{\baselinestretch}{1.5}

\usepackage{listings}
\usepackage{blindtext}
\begin{document}
\blindtext 

\begin{algorithm}[H]
\SetAlgoLined
\KwData{$next\_id, speed,stop\_distance, mac$}
\KwResult{Find the initializer. }
 int $next\_id1$ = find a  record with $speed > 30$ \\ for this $mac$ in the next table;\\
 int $next\_id2$ = find record with $speed <7$ and \\ $stop\_distance < 60$ for this mac in the next table;\\
 \If{$next\_id1 < next\_id2$}{
   find the related $stop\_name$ for this mac;\\
   return  $stop\_name$;
 }
\caption{Algorithm to find intializer.}
\end{algorithm}

\begin{lstlisting}[caption = {MYSQL query to find the initializer.}, label={lst: initializer}]
SELECT speed, stop_name
from next 
where stop_distance < 60 and speed < 7  
and mac = ? and next_id > ?  LIMIT  1
\end{lstlisting}

\clearpage
\end{document}

Verfasst: Sa 3. Okt 2015, 17:01
von Johannes_B
Abstände kannst du mit \vspace einfügen.Eventuell hilft dir auch \medbreak und \bigbreak.

Verfasst: Sa 3. Okt 2015, 17:13
von the_time
also \vspace geht nicht denn ich kriege "! Paragraph ended before \@vspace was complete."

mit \bigbreak and \medbreak funktioniert es.

Danke.

Verfasst: Sa 3. Okt 2015, 17:20
von Johannes_B
\documentclass{article}
\usepackage[ruled]{algorithm2e}
\renewcommand{\baselinestretch}{1.5}

\usepackage{listings}
\usepackage{blindtext}
\begin{document}
\blindtext

\vspace{2cm}

\begin{algorithm}[H]
	\SetAlgoLined
	\KwData{$next\_id, speed,stop\_distance, mac$}
	\KwResult{Find the initializer. }
	int $next\_id1$ = find a  record with $speed > 30$ \\ for this $mac$ in the next table;\\
	int $next\_id2$ = find record with $speed <7$ and \\ $stop\_distance < 60$ for this mac in the next table;\\
	\If{$next\_id1 < next\_id2$}{
		find the related $stop\_name$ for this mac;\\
		return  $stop\_name$;
	}
	\caption{Algorithm to find intializer.}
\end{algorithm}

\begin{lstlisting}[caption = {MYSQL query to find the initializer.}, label={lst: initializer}]
SELECT speed, stop_name
from next
where stop_distance < 60 and speed < 7  
and mac = ? and next_id > ?  LIMIT  1
\end{lstlisting}

\clearpage
\end{document}


Verfasst: Sa 3. Okt 2015, 18:23
von rais
zu 2 und 3:
\documentclass{article}
\usepackage[ruled, linesnumbered, commentsnumbered]{algorithm2e}
\renewcommand{\baselinestretch}{1.5}

\usepackage{listings}
\usepackage{blindtext}
\begin{document}
\blindtext

\vfill

\begin{algorithm}[H]
   \SetAlgoLined
   \KwData{$next\_id, speed,stop\_distance, mac$}
   \KwResult{Find the initializer. }
   int $next\_id1$ = find a  record with $speed > 30$ \\ for this $mac$ in the next table;\\
   \tcc{some comment}
   int $next\_id2$ = find record with $speed <7$ and \\ $stop\_distance < 60$ for this mac in the next table;\\
   \tcp{some other comment}
   \If{$next\_id1 < next\_id2$}{
      find the related $stop\_name$ for this mac;\\
      return  $stop\_name$;
   }
   \caption{Algorithm to find intializer.}
\end{algorithm}

\begin{lstlisting}[caption = {MYSQL query to find the initializer.}, label={lst: initializer}]
SELECT speed, stop_name
from next
where stop_distance < 60 and speed < 7  
and mac = ? and next_id > ?  LIMIT  1
\end{lstlisting}

\clearpage
\end{document}
siehe auch `texdoc algorithm2e'.

VG
Rainer

Verfasst: Sa 3. Okt 2015, 19:09
von Johannes_B
An manchen Tagen fühle ich mich wie im falschen Film: Crosspost