2

I have to write my homework with LaTeX, and I don't know how to add indentation inside text. I want to write my text, like this :

Input  : Sebuah digraf berbobot dengan bobot sisi tak negatif 
Output : Panjang lintasan terpendek dari 

See, the upper colon and bottom colon is indented from Input and Output, but I believe their indentation value is different, because the word "Input" has 5 words, and "Output" is 6. I try to make \indent code and \hspace{size}, but is not fulfill my intention.

2

This can be done with several approaches, three of which are shown below. EDITED to show in the framed environment, per OP's comment. The approaches are:

1) the tabbing environment described in the LaTeX User Guide and Reference Manual. The purpose of \kill is to set the tab indent, but not print out the line. This would be used if it is not the first line which governs the indent of the environment.

2) a TABstack

3) a tabular solution

\documentclass{article}
\usepackage{framed}
\usepackage{tabstackengine}
\begin{document}

\begin{framed}
\begin{tabbing}
Output \= \kill
Input \>: Sebuah digraf berbobot dengan bobot sisi tak negatif\\
Output \>: Panjang lintasan terpendek dari 
\end{tabbing}
\begin{tabbing}
A Really Big Indent \= \kill
Input \>: Sebuah digraf berbobot dengan bobot sisi tak negatif\\
A Really Big Indent \> : blah blah\\
Output \>: Panjang lintasan terpendek dari 
\end{tabbing}
\end{framed}

\begin{framed}
\setstacktabbedgap{.66ex}
\noindent\tabbedLongstack[l]{
Input &: Sebuah digraf berbobot dengan bobot sisi tak negatif\\
Output &: Panjang lintasan terpendek dari 
}
\end{framed}

\begin{framed}
\tabcolsep=.6ex
\noindent\begin{tabular}{lcp{1.6in}}
Input &:& Sebuah digraf berbobot dengan bobot sisi tak negatif\\
Output &:& Panjang lintasan terpendek dari 
\end{tabular}
\end{framed}
\end{document}

enter image description here

The disadvantage of the tabbing approach is that you have to know, in advance, the longest phrase that will cause the indent. That can be avoided with the use of a TABstack, which will automatically figure out the widest entity in the first column.

The 2nd column in the first two approaches will not wrap. If you need wrapping of the 2nd column, the tabular solution can work, with a p column in the last column.

However, none of these approaches will work across a page break.

  • What is the function of \= \kill ? It works, but if I want to add more indentation size, how do I do that? – Yagami Jun 16 '14 at 14:15
  • @Yagami Please see revision – Steven B. Segletes Jun 16 '14 at 14:18
  • It isn't work well inside \begin{framed} code. – Yagami Jun 16 '14 at 14:30
  • Okay, I will try to work again with your code. – Yagami Jun 16 '14 at 14:34
  • @Yagami I verified that all three of my approaches work within a \begin{framed} environment. – Steven B. Segletes Jun 16 '14 at 14:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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