I would like to document a function from OpenCV. I used the lstlisting environment from listings package.



double cv::calibrateCamera 
    InputArrayOfArrays  objectPoints,
    InputArrayOfArrays  imagePoints,
    Size                imageSize,
    InputOutputArray    cameraMatrix,
    InputOutputArray    distCoeffs,
    OutputArrayOfArrays rvecs,
    OutputArrayOfArrays tvecs,
    int                 flags,
    TermCriteria        criteria


The above code was formatted using tabs, as can be seen in the following screenshot that shows them as grey arrows:

enter image description here

As can be seen, the parameter names (that's the second "column": objectPoints, imagePoints, etc.) all line up nicely.

In the result however, additional white space is introduced:


How can I fix this so that the code is rendered verbatim?


As posted the code produces

enter image description here

I would guess your original source has tabs not spaces (this site replaces tabs by spaces)

| improve this answer | |
  • The problem was indeed related to tabs. I added an answer. However, given that the MWE is rather useless, given that it doesn't reproduce the problem as you point out, should I delete my question? Or should I edit my question to state that tabs were used for the formatting? – null Oct 25 '16 at 16:34
  • no I'd leave it helps other people with same issue (It's possibly a duplicate though I'll look...) – David Carlisle Oct 25 '16 at 16:40


If the text should be rendered verbatim, then it must be ensured that tabs are rendered equally.

As it turns out, listings has a few settings, which can be set with this command:


The default value for tabsize is 8 and in my text editor, the size was 4. With the above setting of 4, the code renders just fine.

| improve this answer | |

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.