Since you can't use conditional visibility in document templates, you need:
You can then create a 1 row, 3 column table: Dear | (Title) | (LastName)
What remains is you have to play around with the cell spacing properties, or set manual styles for "padding-left" or "margin-left" - sometimes in these scenarios setting a negative margin-left (for example: margin-left: -10px) on the Title & LastName cells will work.
Since you're using three columns in the table, the actual length of the name / title doesn't matter as it will calculate from the starting point of the cell.
You could also take a look at the email module and use the custom token replace java action to manipulate the string that you pass to the document template.
Regards,
Ronald